On Oct 30, 8:33 am, [EMAIL PROTECTED] wrote:
> # --- <the program> ----
> my $fname = '/volumes/hd/home/kevin/file_test ';  # note file ends
> with a space character
> print "Exists: <$fname>\n" if (-e $fname);
> print "Is a file: <$fname>\n" if (-f $fname);
> open(FH, $fname) or die "Can't open '$fname': $!";
> close(FH) or die "Can't close '$fname': $!";
>
> # --- <the output> ---
> Processing file: file_test
> Exists: <file_test >
> Is a file: <file_test >
> Can't open 'file_test ': No such file or directory at testopen.pl line
> 42.
>
> # -- <the question> ---
>
> Is this a known bug in Perl 5.8.6?

In my first response (which isn't showing up via Google Groups yet), I
referred to perldoc -f open.  Here is the relevant passage from that
documentation:

             The filename passed to 2-argument (or 1-argument)
             form of open() will have leading and trailing
             whitespace deleted, and the normal redirection
             characters honored.  This property, known as "magic
             open", can often be used to good effect.  A user
             could specify a filename of "rsh cat file |", or you
             could change certain filenames as needed:

                 $filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/;
                 open(FH, $filename) or die "Can't open $filename:
$!";

             Use 3-argument form to open a file with arbitrary
             weird characters in it,

                 open(FOO, '<', $file);

             otherwise it's necessary to protect any leading and
             trailing whitespace:

                 $file =~ s#^(\s)#./$1#;
                 open(FOO, "< $file\0");


Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to