Kevin Pfeiffer wrote: > > Hi John, Hello,
> In article <[EMAIL PROTECTED]>, John W. Krahn wrote: > [...] > > perldoc -q filehandle > > > > [snip] > > Hmmm... lots to digest here. One question. An example mentioned is: > > <Excerpt from="perldoc -q filehandle"> > As of perl5.6, open() autovivifies file and direc� > tory handles as references if you pass it an > uninitialized scalar variable. You can then pass > these references just like any other scalar, and > use them in the place of named handles. > > open my $fh, $file_name; > > open local $fh, $file_name; > > print $fh "Hello World!\n"; > > process_file( $fh ); > > Before perl5.6, you had to deal with various type� > glob idioms which you may see in older code. > > open FILE, "> $filename"; > process_typeglob( *FILE ); > process_reference( \*FILE ); > </excerpt> > > The Llama book, etc. teach using file handles (I think): > open FILE, "> $filename"; # etc. > > But this mentions instead: > open my $fh, "> ", $filename; > > "$fh" seems simpler (since I have only a passing idea of what globs are). > Which should one be using? (If it makes a difference). If you have version 5.6 or newer you should probably use the three argument open() with autovivified filehandles as it is safer than using the one or two argument forms. The documentation for open() explains some of the problems. If you use lexically scoped filehandles then the file will be closed when the filehandle goes out of scope. open my $fh, '>', $file or die "open $file: $!"; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
