Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Spotting an empty array as argument

by ikegami (Patriarch)
on Mar 26, 2021 at 19:23 UTC ( [id://11130393]=note: print w/replies, xml ) Need Help??


in reply to Spotting an empty array as argument

You can't pass arrays (or hashes) to subs, only a sequence of zero or more scalars. There is no difference between

f(@a)
and
f($a[0], $a[1], $a[2], ...)

so you can't distinguish

my @empty; f(@empty)
from
f()

At best, you can use prototypes to change what scalars are passed to a sub.

sub f(;\@)
will allow
f(@a) # Calls &f(\@a)
and
f() # Calls &f()
but not
f($x, $y)

What you want to achieve, however, can't be achieved using prototypes. You'd have to use something like Devel::CallParser.

Seeking work! You can reach me at ikegami@adaelis.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11130393]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-16 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found