Hi ww,
When I run the OP's script with use warnings; added I don't see a warning for printing "@a" but I do get one for print $a[-2] since there is only one element in the OP's array. Here is the warning I get:
Use of uninitialized value in print at C:\usr\pm\sort\1164677.pl line 7.
When you print an array inside of double quotes it adds a space by default between the elements or whatever the output field list separator, "$," '$"', is set to. How do I print an array with commas separating each element?
Update: I forgot to mention also at the line (my @newstring) = sort {$a <=> $b} @numbers; you don't need the parentheses since defining an array is already in array context. These are nitpicky comments since your program works and answered the OPs questions, but it's my 2 cents worth.
Update: Fixed the separator as pointed out by AnomalousMonk
In reply to Re^2: not able to get last index of array
by Lotus1
in thread not able to get last index of array
by lakshmikant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |