in reply to question regarding "v" flag of printf
Perl interprets each character in the string as its index in your character set. (In ASCII, character 49 is "1").
To split a string of digits, use:
my @digits = split //, '123';For your second case, there are a few ways to do it, but unpack is a popular method:
my @nums = unpack '(A3)*', '100200300';Note that both of these solutions don't actually care whether the strings contain digits or other characters like letters; if that matters to you, be sure to validate your input.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: question regarding "v" flag of printf
by lightoverhead (Pilgrim) on May 23, 2013 at 16:22 UTC | |
by Anonymous Monk on May 23, 2013 at 16:48 UTC | |
by lightoverhead (Pilgrim) on May 23, 2013 at 16:57 UTC | |
by Anonymous Monk on May 23, 2013 at 17:55 UTC | |
by Anonymous Monk on May 23, 2013 at 17:59 UTC | |
by lightoverhead (Pilgrim) on May 23, 2013 at 18:21 UTC |