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?

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

.



Relevant Pages

  • Re: determine default filename encoding
    ... > Suse tech support for the way filename characters are represented, ... Characters are characters - just bytes. ... Then if that coding differed from the LANG coding ... filenames that were written in encoding X as they were written, ...
    (comp.os.linux.setup)
  • Re: unix filename restriction
    ... underscore _ and the dot. ... You could use other characters, ... never met a *human* defined path of more than 80 chars (most of the ... If you want to be very sure, limit your filename to the DOS limit of 8 ...
    (comp.os.linux.development.apps)
  • Re: Error Message: "The File Name is Not Valid or Too Long...."
    ... I, then, proceed to name that file using only valid characters. ... the destination folder. ... That is not counting the drive letter and slashes or the filename itself. ... (Again - not counting the extension/dot.) ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: Cannot delete files
    ... There HAS to be an 8.3 filename! ... I've not been brave enough to tell it Yes on THIS folder, ... characters don't look quite the same in this email font; ... but the SFN was "NOD~1.EE". ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: Characters allow in the title
    ... I guess that like many features in Word, this is one that is sort of there ... Charles Kenyon ... >> characters. ... >>> cause the filename taken from the title field to break. ...
    (microsoft.public.word.newusers)