in reply to from array to hash
%b = map { $_ => 1 } grep defined, @a;
or
%b = map { defined ? ($_ => 1) : () } @a;
or you could avoid getting undef in the first place by using splice instead of delete or undef to delete the element from the array:
@a = qw( a b c d ); # Delete 1 starting at index 2. # What used to be at index 3 is now at index 2. splice(@a, 2, 1); print("\@a has ", scalar(@a), "elements.\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: from array to hash
by jeanluca (Deacon) on Mar 09, 2006 at 15:44 UTC | |
by friedo (Prior) on Mar 09, 2006 at 15:48 UTC | |
by ikegami (Patriarch) on Mar 09, 2006 at 17:20 UTC |