Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Render numeric sequence as array of letters

by Not_a_Number (Prior)
on May 20, 2003 at 17:35 UTC ( [id://259520]=note: print w/replies, xml ) Need Help??


in reply to Render numeric sequence as array of letters

Maybe a bit late, but there's an issue in the OP's code that nobody else has explicitly mentioned, namely that the first line:

my @original_array = qw(5, 100, 2, 8, 40);

will actually put the commas in @original_array along with the numbers themselves, as would have been pointed out if -w had been on

In this instance, it doesn’t matter much, since if I understand correctly, perl will uncomplainingly do a numerical sort on strings as long as each begins with what it interprets as a number.

In other cases, however, putting unneeded commas in a qw(list) could lead to some surprises. Try this:

my @ary = qw ( 1, foo, 2, bar5, 33 ); for ( @ary ) { #print only the numbers: print if /^\d+$/ }

Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-04-25 11:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found