Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Returning first element of an array from a function

by matija (Priest)
on Mar 17, 2004 at 07:49 UTC ( [id://337247]=note: print w/replies, xml ) Need Help??


in reply to Returning first element of an array from a function

If you're using someone else's function, and only want the first element, you can do something like this:
$val=(split(/\./,$bar))[0];
If you're writing your own function, you can use the wantarray function to tell if the function has been called in an array or scalar context:
sub flexible { .... if (wantarray) { return @arr; } else { return $scal; } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-24 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found