in reply to Length of strings in an array
Hello shabird,
it gives the length of the string but it also counts the enter key
You should chomp the string to remove the trailing newline before finding the length.
the order is not sorted although i have used to sort function for that.
By default, sort sorts in lexicographical order, so 100 comes before 90 because 1 comes before 9. To sort numerically, do this:
my @array = sort { $a <=> $b } $frstLength, $scndLength, $trdLength, $ +frthLength;
You should also begin your script with use strict;, which forces you to declare each variable with my. (This is a good thing! It will save you a lot of debugging time in the long run.)
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Length of strings in an array
by shabird (Sexton) on Sep 20, 2020 at 16:53 UTC | |
by BillKSmith (Monsignor) on Sep 20, 2020 at 18:36 UTC |