processing array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • perlaroha
    New Member
    • Oct 2009
    • 3

    #1

    processing array

    I have an array @arr as:

    aa bb cc
    dd ee ff
    gg hh kk
    tt yy uu

    I need to extract the second coulmn from this & push it to another array called @brr so that it contains only

    bb
    ee
    hh
    yy
  • toolic
    Recognized Expert New Member
    • Sep 2009
    • 70

    #2
    Assuming @arr is an Array-of-arrays:

    Code:
    use strict;   
    use warnings;
    use Data::Dumper;
    
    my @arr = (
      [qw(aa bb cc)],
      [qw(dd ee ff)],
      [qw(gg hh kk)],
      [qw(tt yy uu)]
    );
    my @brr;
    push @brr, $_->[1] for @arr;
    print Dumper(\@brr);
    
    __END__
    
    $VAR1 = [
              'bb',
              'ee',
              'hh',
              'yy'
            ];

    Comment

    • perlaroha
      New Member
      • Oct 2009
      • 3

      #3
      Thanks toolic for the reply.

      Comment

      Working...