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
|
|---|