muthm has asked for the wisdom of the Perl Monks concerning the following question:

Dear wise monks.
I have stumbled over a piece of code that uses a syntax like < a b c > to specify a list of values, like in
$ perl -we 'print "$_\n" for < a b c >;' a b c
or
my $array_ref = [< 1 2 3 4 5 >];

Playing around with it a bit, I found out that even things like

use Data::Dump < pp >;
seem to work (as long as what is inside the angle brackets does not look too much like a file handle).

It seems like < ... > works a lot like qw(...) in that there are no commas needed to separate the parts, but also a bit like qq(...) (or plain "...") in that variables are substituted. Like in this example:

$ perl -we 'use Data::Dump < pp >; $x="foo"; pp <a 2 $x b>;' ("a", 2, "foo", "b")

I am wondering why I have never seen this syntax in any literature (or do I just get old and forget things?).
I would therefore like to ask for enlightenment about where to find any documentation about this syntax.
(A pointer to a relevant section of https://perldoc.perl.org/ would be much admired!).

Thank you for your help!

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

    G'day muthm,

    Welcome to the Monastery.

    $ perl -MO=Deparse,-p -e 'print "$_\n" for < a b c >;' use File::Glob (); print(("$_\n")) foreach (glob(' a b c ')); -e syntax OK

    Documentation for your admiration :-)

    — Ken

Re: Can't find any documentation on < a b c > syntax for lists
by haukex (Archbishop) on Feb 14, 2023 at 07:19 UTC
Re: Can't find any documentation on < a b c > syntax for lists
by jwkrahn (Abbot) on Feb 14, 2023 at 03:27 UTC

    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

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

Re: Can't find any documentation on < a b c > syntax for lists
by muthm (Sexton) on Feb 14, 2023 at 16:28 UTC

    Thank you all, I have learned a lot!
    Mostly, that I will stick to qw(...) in the future. Safety first :-).

    My belief is strengthened!

      "Mostly, that I will stick to qw(...) in the future."

      Just be aware of this common mistake:

      $ perl -we 'print "$_\n" for qw{ a b c };' a b c $ perl -we 'for qw{ a b c } { print "$_\n"; }' Missing $ on loop variable at -e line 1. $ perl -we 'for (qw{ a b c }) { print "$_\n"; }' a b c

      You can leave the parentheses off when for is used as a statement modifier; but not when it introduces a compound statement. See perlsyn for more about that.

      It's a common mistake because, although it was never really valid, Perl didn't report a problem until v5.14.0. For details, see:

      — Ken