[ABE.pm] Proper open() syntax?
Ricardo SIGNES
rjbs-perl-abe at lists.manxome.org
Sat Aug 19 05:58:52 PDT 2006
* Tom Freedman <tfreedman at iqep.com> [2006-08-18T22:55:05]
> my $output_file;
> open($output_file, '>', $ARGV[1] || STDOUT) or die "$!";
>
> [ ... ]
>
> Now, the above works fine, but I don't understand why the first version
> didn't work. Is there a way to open STDOUT with the three-arg version
> of open()?
STDOUT is, itself, a filehandle. You can't put it in the third position of
three-arg open, which must contain a filename or string reference.
What you want is something like:
my $output;
if ($ARGV[1]) { open $output, '>', $ARGV[1] }
else { $output = \*STDOUT }
...but then again, I think that the REAL way to do this is to actually use "-"
as the filename or, as I would suggest, to ALWAYS print to STDOUT, and use
redirection to write to a file.
yourprogram script.txt > output.txt
> P.S. - All the Mac talk makes me nostalgic for my PowerMac 9500 w/ MacOS
> 8!
I had a PowerMac 6100 and a PowerBook Duo 280c, and I worked on 7200's a BU.
While they were pleasant to use, OS X is really a whole different experience.
It's like a grown-up OS with a command line and an init(8)!
--
rjbs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.pm.org/pipermail/abe-pm/attachments/20060819/f7416dac/attachment.bin
More information about the ABE-pm
mailing list