in reply to Deleting records from an array
output:use strict; use warnings; use Data::Dumper; my %hash = ( a => 1, n => 1, z => 1, ); my @ary = qw( a b n m y z ); for my $key ( keys %hash ) { for my $elem (@ary) { next if not defined $elem; if ( $elem =~ $key ) { $elem = undef; } } } print Dumper \@ary;
It works because $elem in this kind of loop is magical... it's an 'alias' (so I guess a pointer) to the real elements of array.$VAR1 = [ undef, 'b', undef, 'm', 'y', undef ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Deleting records from an array
by Anonymous Monk on Dec 22, 2014 at 08:37 UTC | |
by Anonymous Monk on Dec 22, 2014 at 08:40 UTC |