in reply to Re^6: Determining what line a filehandle is on
in thread Determining what line a filehandle is on

On a related note, isn't
$a= undef; open ($a, "<file.txt");
a fairly new thing? That is, we used to have to use tricks to create a reference to an anonymous filehandle first, and then open it. Now filehandles are autovivafing. I think that may be one reason why getting away from plain HANDLE's is historicaly a pain, but isn't as bad anymore.

Replies are listed 'Best First'.
Re^8: Determining what line a filehandle is on
by tadman (Prior) on Jul 08, 2001 at 22:29 UTC
    I believe this was introduced in Perl 5, so your definition of "new" is obviously a matter of perspective.

    In fact, one of the things that I'm wondering is if you are supposed to be using "old-fashioned" file handles at all. They are more difficult to localize and pass as parameters. Using a "GLOB-ref", as these file handles are, is much more convenient, given even the one-character "penalty" for the $.

    Update:
    The "traditional" way is along the lines of:
    local (*FOO); open (FOO, $foo_file) || die "Could not open $foo_file\n"; DoStuffOnHandle(\*FOO); close (FOO);
    Versus the new "lexical" way:
    my $foo; open ($foo, $foo_file) || die "Could not open $foo_file\n"; DoStuffOnHandle($foo); close ($foo);
      Actually this was introduced in 5.6.0, so new really isn't that relative. In 5.005_03 and earlier you have to jump an extra hoop:
      my $foo = do {local *FH}; # etc as above
      or if you prefer a different look, you can use Symbol and then do it with:
      my $foo = gensym(); # And so on
      But with 5.6 it autovivifies for you, and that is rather nice.
      Well, that convinces me. Since there is no real issue, I'll use lexical variables going forward.