Re: Perl 5.8.6 bug in open()?



<google@xxxxxxxxx> 10/30/2007 6:33 AM >>>
<snip>
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?

No, it's a documented feature of the open call. See perldoc -f open:

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");

Change your open call to use the three argument version and you should be fine.

Hope this helps,

Jeff Eggen
IT Analyst
Saskatchewan Government Insurance
Ph (306) 751-1795
email jeggen@xxxxxxxxx

This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the named addressee, please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that using, disclosing, copying or distributing the contents of this information is strictly prohibited.
.



Relevant Pages

  • Re: bonding: cannot remove certain named devices
    ... I believe the only invalid character in an interface name is '/'. ... This should allow for whitespace in the filename. ... since we would allow trailing whitespace. ...
    (Linux-Kernel)
  • Re: Perl 5.8.6 bug in open()?
    ... Processing file: file_test ... The filename passed to 2-argument ... characters honored. ...
    (perl.beginners)
  • Re: Hello and a question
    ... They like you to bottom post of this list. ... hard work is done by split which will breaks the filename into two ... perldoc -f -X #' for info on file tests ...
    (perl.beginners)
  • RE: how the print the first 7 letter of file name
    ... Your solution will return only the first 7 characters of the filename. ... This happens to be "NewProcess". ... perldoc -q "What is the difference between a list and an array?" ... E-mail transmission cannot be guaranteed to be secure or error-free ...
    (perl.beginners)
  • Re: filehandles
    ... "readlineon closed filehandle FILENAME at ..." ... You _should_ have used the strict pragma which ... would have complained to you that $file and @protein aren't ... or "perldoc perldoc" if you wonder about that perldoc ...
    (comp.lang.perl.misc)