Section 8.3. The Even Better Way


8.3. The Even Better Way

So far, our examples have shown the two-argument form of open, but that actually has a catch: the open mode and the filename both live in the second argument. That means that we have to store two different things in one string, and we have to trust Perl to be able to figure it out.

To get around that, we break the second argument into two separate arguments.

 open my $log_fh, '>>', 'castaways.log'         or die "Could not open castaways.log: $!"; 

This three-argument form has the added advantage of access to the Perl IO filters. We won't go into too much detail here.[*] The open function's entry in perlfunc is over 400 lines, even though it has its own perldoc tutorial, perlopentut.

[*] Although brian does in "Get More Out of Open," The Perl Journal , October 31, 2005, http://www.tpj.com/documents/s=9923/tpj1130955178261/bdf_open.htm.




Intermediate Perl
Intermediate Perl
ISBN: 0596102062
EAN: 2147483647
Year: N/A
Pages: 238

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net