At 08:49 -0400 2001.08.05, Greg London wrote:
>first, could someone tell me when did perl start
>supporting an open function that handles 3 parameters?
> open ($handle, $mode, $filename);
perl 5.6.
>is this the preferred usage when opening a file now?
Not that I can tell. If I want to do a safe open, I just use sysopen.
>second, is using a reference to a filehandle
>the preferred way of passing filehandles
>around higgly piggly?
>
> my $fh = \*MYHANDLE;
>
> open($fh, $read, $name);
> print_next_line($fh);
> close($fh);
>
> sub print_next_line
> {
> my $handle = shift;
> my $line = <$handle>;
> print "line is $line";
> }
>
>I've seen the first line written like this too:
> my $fh = *MYHANDLE;
>
>what's the difference? advantages/disadvantages?
If you are creating a new filehandle, then don't do either. Prior to perl
5.6, use:
use Symbol;
my $fh = gensym();
In perl 5.6 and later, just do:
open(my $fh, $filename) or die $!;
This is called filehandle "autovivification": the filehandle automatically
springs to life.
If you are passing a filehandle, well, most of the time you wouldn't ever
have a raw filehandle anymore, since you are using lexical variables via
gensym() or autovification. But it is better to use \*FILEHANDLE if you
must.
>will all file IO functions take a reference
>like this?
Anything that takes a filehandle should, yes. Either *FOO or \*FOO should
work.
--
Chris Nandor [EMAIL PROTECTED] http://pudge.net/
Open Source Development Network [EMAIL PROTECTED] http://osdn.com/