in reply to Re: not able to get last index of array
in thread not able to get last index of array
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: not able to get last index of array
by AnomalousMonk (Archbishop) on Jun 04, 2016 at 15:50 UTC | |
by Lotus1 (Vicar) on Jun 04, 2016 at 16:09 UTC |