in reply to Spotting an empty array as argument

To distinguish between no argument and an empty array, you can use the ;\@ prototype. It makes it impossible to specify more than one argument, though:
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; sub mysay (;\@) { my ($arr) = @_; if (defined $arr) { print "$_\n" for @$arr; } else { print "$_\n"; } } my @arr2 = qw( Two/1 Two/2 ); mysay(@arr2); my @arr1 = qw( One ); mysay(@arr1); $_ = "Don't show"; my @arr0; mysay(@arr0); $_ = "Underscore"; mysay(); # This doesn't compile. # mysay(qw(a b c));
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Spotting an empty array as argument
by Chuma (Scribe) on Mar 25, 2021 at 21:49 UTC

    Neat! Although of course in this case I do need to specify more than one argument...

Re^2: Spotting an empty array as argument
by LanX (Saint) on Mar 25, 2021 at 22:08 UTC
    > It makes it impossible to specify more than one argument, though:

    I think you are confusing @ with \@ . The former will swallow the whole list

    DB<40> sub my_say (;\@$$$) { dd \@_ } DB<41> my_say @a [["a1", "a2", "a3"]] DB<42> my_say @a,$a [["a1", "a2", "a3"], "A"] DB<43> sub tst (@) { dd @_ } DB<44> tst @a ("a1", "a2", "a3") DB<45> tst @a,2 ("a1", "a2", "a3", 2)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      > I think you are confusing @ with \@.

      No, I mean what you can try by uncommenting the last line.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        Oh, I see.

        I just experimented with the newer prototypes like + and _ but it's still a PITA. :/

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery