Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Assign result of map to scalar variable

by runrig (Abbot)
on Jul 18, 2013 at 20:30 UTC ( #1045183=note: print w/ replies, xml ) Need Help??


in reply to Assign result of map to scalar variable

Capturing parens return an array of the results, and you only have one set of capturing parens, so you can just return that:

my ($val) = map { /^\*\s\(?([^\)]+)\)?/} @GET_STRING; # Or (as others have suggested) my ($val) = map { /^\*\s\(?([^\)]+)\)?/ ? $1 : () } @GET_STRING;


Comment on Re: Assign result of map to scalar variable
Download Code
Replies are listed 'Best First'.
Re^2: Assign result of map to scalar variable
by AnomalousMonk (Abbot) on Jul 18, 2013 at 21:08 UTC
    my ($val) = map { /^\*\s\(?([^\)]+)\)?/} @GET_STRING;

    ++     Simplest by far... so far.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2015-07-28 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls