G Nagasri Varma has asked for the wisdom of the Perl Monks concerning the following question:

How can we calculate , length of each element in an array?

Replies are listed 'Best First'.
Re: length of each element in an array?
by choroba (Cardinal) on Dec 03, 2015 at 09:16 UTC
    You need to iterate over the array and call length for each of its members.
    for my $member (@array) { print length $member, "\n"; }

    Or, if you like shorter code,

    print length, "\n" for @array;

    If you want to create an array of lengths, use map:

    my @lengths = map length, @array;
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      for my $member (@array)
      {
      print length $member, "\n";
      }

      The above option worked fine.I am able to view the length of each element in an array. But I want the list of elements of length greater than n size to be sent to a new array.
        Great! You should have said it earlier. That's exactly the task for grep:
        my @longer = grep $n < length, @array;
        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,