Harry Putnam <rea...@newsguy.com> asked: > I see advanced users here using various styles of open().
[three argument open] > Is there something beyond style that makes those methods better than > what appears to be a simpler format: [two argument open] Allow me to quote "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"); (this may not work on some bizarre filesystems). One should conscientiously choose between the magic and 3-arguments form of open(): open IN, $ARGV[0]; will allow the user to specify an argument of the form "rsh cat file |", but will not work on a filename which happens to have a trailing space, while open IN, '<', $ARGV[0]; will have exactly the opposite restrictions. I hope this answers your question ;-) Cheers, Thomas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/