Connecting Tech Pros Worldwide Forums | Help | Site Map

processing array

Newbie
 
Join Date: Oct 2009
Posts: 3
#1: 4 Weeks Ago
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

Newbie
 
Join Date: Sep 2009
Posts: 15
#2: 4 Weeks Ago

re: processing array


Assuming @arr is an Array-of-arrays:

Expand|Select|Wrap|Line Numbers
  1. use strict;   
  2. use warnings;
  3. use Data::Dumper;
  4.  
  5. my @arr = (
  6.   [qw(aa bb cc)],
  7.   [qw(dd ee ff)],
  8.   [qw(gg hh kk)],
  9.   [qw(tt yy uu)]
  10. );
  11. my @brr;
  12. push @brr, $_->[1] for @arr;
  13. print Dumper(\@brr);
  14.  
  15. __END__
  16.  
  17. $VAR1 = [
  18.           'bb',
  19.           'ee',
  20.           'hh',
  21.           'yy'
  22.         ];
  23.  
Newbie
 
Join Date: Oct 2009
Posts: 3
#3: 4 Weeks Ago

re: processing array


Thanks toolic for the reply.
Reply