in reply to anonymous filehandes?

One difference is that your "anonymous filehandling" will also work on STDIN, but your "explicit filehandling" will not.

For example, the following will print something:

cat file1.txt file2.txt | anonymous.pl

Replies are listed 'Best First'.
Re^2: anonymous filehandes?
by Anonymous Monk on Jul 09, 2007 at 16:18 UTC

    I came up with the term anonymous filehandles on-the-fly as I didn't know what else it is called.

    Is there a formal name for this feature?

    Thanks.

      Perl Cookbook just refers to it as "<>" and doesn't mention any name for it.

      Regarding your other response, yes, perl is smart enough to automagically close any open files when the program exits, regardless of how/when they were opened. It may close files opened by <> sooner (e.g., when each of them hits EOF), but I haven't found anything which clearly states that one way or the other.

        If you read perlop's description of <> (the "null filehandle" in its nomenclature) it expands out the construct to:

        unshift(@ARGV, '-') unless @ARGV; while ($ARGV = shift) { open(ARGV, $ARGV); while (<ARGV>) { ... # code for each line } }

        When you re-open any existing filehandle the underlying file is implicitly closed; so each time through the loop the prior file will be closed before the handle is reused.