Perhaps you could turn the array containing a flat list of ids and names into an AoH and use grep to pull out the odd ids when building it.
knoppix@Microknoppix:~$ perl -MData::Dumper -E ' > @studentInfo = qw{ > 001 John > 002 Mary > 003 Tom > }; > @oddStudents = > map { { id => $_->[ 0 ], name => $_->[ 1 ] } } > grep { $_->[ 0 ] % 2 } > sub { > push @ret, [ shift, shift ] while @_; > return @ret; > }->( @studentInfo ); > say Data::Dumper->Dumpxs( > [ \ @oddStudents ], > [ qw{ *oddStudents } ] > );' @oddStudents = ( { 'name' => 'John', 'id' => '001' }, { 'name' => 'Tom', 'id' => '003' } ); knoppix@Microknoppix:~$
I hope this is helpful.
Cheers,
JohnGG
In reply to Re: Find odd/even elements of array
by johngg
in thread Find odd/even elements of array
by perlPractioner
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |