in reply to Re^2: Can't find any documentation on < a b c > syntax for lists
in thread Can't find any documentation on < a b c > syntax for lists

Why are these different?
perl -MO=Deparse,-p -e 'print "$_\n" for < a >;'
use File::Glob ();
print("$_\n") foreach (glob(' a '));

perl -MO=Deparse,-p -e 'print "$_\n" for <a>;'
print("$_\n") foreach (readline(a));

Replies are listed 'Best First'.
Re^4: Can't find any documentation on < a b c > syntax for lists
by Athanasius (Archbishop) on Feb 14, 2023 at 07:08 UTC

    From perlop (boldface added for emphasis):

    If what's within the angle brackets is neither a filehandle nor a simple scalar variable containing a filehandle name, typeglob, or typeglob reference, it is interpreted as a filename pattern to be globbed, and either a list of filenames or the next filename in the list is returned, depending on context. This distinction is determined on syntactic grounds alone. That means <$x> is always a readline() from an indirect handle, but <$hash{key}> is always a glob(). That's because $x is a simple scalar variable, but $hash{key} is not--it's a hash element. Even <$x > (note the extra space) is treated as glob("$x "), not readline($x).

    Hope that helps,

    Athanasius <°(((><contra mundum סתם עוד האקר של פרל,

Re^4: Can't find any documentation on < a b c > syntax for lists
by LanX (Saint) on Feb 14, 2023 at 14:33 UTC
    > Why are these different?

    > perl -MO=Deparse,-p -e 'print "$_\n" for < a >;'

    > perl -MO=Deparse,-p -e 'print "$_\n" for <a>;'

    a could be an old-style bare-word file-handle, but " a " can't

    think

    • open a, "<", "filename"
    instead of the common FH

    one of the reasons why ppl are encouraged to use lexical filehandles:

    • open my $fh, "<", "filename"

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

  • update: added code tags in citations, thanks hippo++
Re^4: Can't find any documentation on < a b c > syntax for lists
by ikegami (Patriarch) on Feb 14, 2023 at 15:38 UTC

    From this StackOverflow answer,

    • <> means readline(ARGV)
    • <IDENTIFIER> means readline(IDENTIFIER)
    • <$IDENTIFIER> means readline($IDENTIFIER)
    • <...> (anything else) means glob(qq<...>)
        <...> (anything else) means glob(qq<...>)
      Anything? Except this:
      perl -MO=Deparse,-p -e 'print "$_\n" for <<>>'
      print("$_\n") foreach (<<>>);

      Perl waits for input:

      echo fubar | perl -e 'print "$_\n" for <<>>'
      fubar

        Different operator. I also didn't cover <<EOF eventually followed by >, or $x<123 eventually followed by a >, etc.