Re: Perl 5.8.6 bug in open()?



On Oct 30, 8:33 am, goo...@xxxxxxxxx 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?

It's known, but I don't know that it qualifies as a bug. When you
use the two argument form of open, Perl is looking for both the
filename and mode, concatenated together, possibly with spaces
separating them. Since your file ends in a space, you can't use this
shortcut. In reality, you should NEVER use this short cut.

Use the three-argument form of open, and you'll be fine:

open my $FH, '<', $fname or die "Cannot open '$fname': $!";

perldoc -f open
for more information

Paul Lalli

.



Relevant Pages

  • Re: Perl 5.8.6 bug in open()?
    ... with a space character ... Processing file: file_test ... Is this a known bug in Perl 5.8.6? ...
    (perl.beginners)
  • Perl 5.8.6 bug in open()?
    ... with a space character ... Processing file: file_test ... Is this a known bug in Perl 5.8.6? ...
    (perl.beginners)
  • float bug? perl 5.8, DBI and oracle 10.2.0
    ... I am having trouble with a tricky little beast that smells like a bug, ... I noticed this problem while upgrading a large software from perl 5.6.2 to ... I still don't know where to locate the bug. ... using an integer value instead of a float. ...
    (perl.dbi.users)
  • Re: Perl qx// broken with OpenVMS 8.x
    ... This is perl, v5.8.6 built for VMS_AXP ... I'm looking for information about the qx// bug being logged and a time ... The qx operator is a special quoting operator that spawns a command to ... script suppresses error messages and does not do any error checking, ...
    (comp.os.vms)
  • Re: Perl CGI.pm POST_MAX problem in FC7 - when will latest version be available in archives?
    ... the CGI script will peg the CPU until the web server ... new upstream perl release will need to include an updated CGI.pm. ... This could get updated via a patch. ... patch CGI.pm to avoid the specific bug you're encountering (CPAN bug ...
    (Fedora)