By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,811 Members | 1,978 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,811 IT Pros & Developers. It's quick & easy.

processing array

P: 3
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
Oct 29 '09 #1
Share this Question
Share on Google+
2 Replies


Expert
P: 70
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.  
Oct 30 '09 #2

P: 3
Thanks toolic for the reply.
Oct 30 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.