Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Converting quoted strings to numbers in array

by haukex (Archbishop)
on Apr 24, 2017 at 13:01 UTC ( [id://1188760]=note: print w/replies, xml ) Need Help??


in reply to Re: Converting quoted strings to numbers in array
in thread Converting quoted strings to numbers in array

I'm not sure if using a ternary operator inside map is considered un idiomatic, but it seems to work.

I'd say it's idiomatic, and can even be shortened since $_ is used as the default argument for many functions (including oct) and for regexes that aren't bound to something via =~:

use Data::Dump; my @arr = qw/ 10 20 0b1101 0xF 023 /; dd @arr; my @converted = map {/^0/ ? oct : $_} @arr; dd @converted; __END__ (10, 20, "0b1101", "0xF", "023") (10, 20, 13, 15, 19)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found