in reply to Converting quoted strings to numbers in array
Hi,
Thank you for taking time to reply to my query. Using the suggestions here, I have come up with the following solution.
use strict; use warnings; my @arr = qw(10 20 0b1101 0xF 023); my @converted = map {$_ =~ /^0/ ? oct($_) : $_ } @arr; print "@arr\n"; print "@converted\n";
The output seems satisfactory:
C:\>perl practice.pl 10 20 0b1101 0xF 023 10 20 13 15 19
I'm not sure if using a ternary operator inside map is considered un idiomatic, but it seems to work.
Thank you all, thank you very much. This I know would seem trivial to you, but it's fixing something I've been fighting in my head from a while.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Converting quoted strings to numbers in array
by haukex (Archbishop) on Apr 24, 2017 at 13:01 UTC |