in reply to Can't find any documentation on < a b c > syntax for lists

It's a file glob. It's looking for the files 'a', 'b' and 'c' and then returns that list.

perldoc -f glob

Naked blocks are fun! -- Randal L. Schwartz, Perl hacker
  • Comment on Re: Can't find any documentation on < a b c > syntax for lists

Replies are listed 'Best First'.
Re^2: Can't find any documentation on < a b c > syntax for lists
by ikegami (Patriarch) on Feb 14, 2023 at 05:38 UTC

    <a b c> doesn't look for files. But <[abc]> and <*> would.

      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));
      

        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 סתם עוד האקר של פרל,

        > 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++

        From this StackOverflow answer,

        • <> means readline(ARGV)
        • <IDENTIFIER> means readline(IDENTIFIER)
        • <$IDENTIFIER> means readline($IDENTIFIER)
        • <...> (anything else) means glob(qq<...>)