Re: More died on open command (from 55103)
From: John W. Krahn (krahnj_at_acm.org)
Date: 11/11/03
- Next message: Drieux: "Re: Peculiar problem using LWP::UserAgent"
- Previous message: Drieux: "Re: Died on open command"
- In reply to: Ganesh Shankar: "More died on open command (from 55103)"
- Next in thread: Drieux: "Re: More died on open command (from 55103)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: beginners@perl.org Date: Mon, 10 Nov 2003 15:24:07 -0800
Ganesh Shankar wrote:
>
> Hello all,
Hello,
> I tried modifying the open command ar suggested and got the enclosed
> errors. Also, I'm working with Activestate Activeperl 5.6 on a Windows
> 2000. Also, from the syntax of the readdir example, the test is to the
> left of the readdir command. Does this mean I should place my file
> processing block to the left of the readdir command. That would be one
> ugly statement.
>
> [snip]
>
> use warnings;
> use strict;
>
> my @files = ();
> my $folder = 'input';
> # Open the input folder
> unless (opendir(FOLDER, $folder)) {
> print "Cannot open folder $folder!\n\n";
> exit;
> }
>
> #read the contents of the folder (files and subfolders)
>
> chdir($folder); #added this line after failing with open commands below.
>
> print "Switching to folder $folder!\n\n"; # It's going to the correct
> folder
>
> @files = readdir(FOLDER);
>
> #Close the folder
>
> print "\n\n Here are the files in the folder\n";
> #print out the filenames, one per line
> print join( "\n", @files), "\n";# Prints out correct filenames
>
> closedir(FOLDER);
>
> foreach my $seqfilename (@files){
>
> $seqfilename = '';
> open (TXTFILE,"<$seqfilename") or die $!; #dies on this line.Replace with
This won't work because it is trying to open $seqfilename in the current
directory.
> open (TXTFILE,"<$folder/$seqfilename") or die $!; #Invalid argument at this line. Replace with
Windows apparently sends an EINVAL ("Invalid argument") when there are
certain non-printable characters in the file name! (Who knew?)
http://mail.python.org/pipermail/python-list/2002-March/090323.html
> open (TXTFILE,"<$folder\$seqfilename") or die $!; #No such file or directory error at this line
This won't work because the backslash will escape the dollar sign. If
you want the backslash character in a double quoted string you will have
to escape it (precede it with a backslash.)
John
-- use Perl; program fulfillment
- Next message: Drieux: "Re: Peculiar problem using LWP::UserAgent"
- Previous message: Drieux: "Re: Died on open command"
- In reply to: Ganesh Shankar: "More died on open command (from 55103)"
- Next in thread: Drieux: "Re: More died on open command (from 55103)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|