[Chicago-talk] Limiting a hash, or producing an interesting list
Mike Pastore
mike at oobak.org
Tue Nov 25 09:59:56 CST 2003
Jay,
After playing around with it for a bit, I think your way is best if you
want to keep separate %all and %interesting maps. But if you don't mind
modifying the original list, here's an alternative method:
my @all = qw/this that other some junk trash need/;
my @interesting = qw/this that need/;
my %search = map { $_ => 1 } @interesting;
for(my $i = $#all; $i >= 0; $i--) {
splice @all, $i, not exists $search{$all[$i]};
}
Overall, I think your way is best.
--
Mike Pastore
mike at oobak.org
On Tue, 2003-11-25 at 07:17, Jay Strauss wrote:
> Hi,
>
> I'm not sure how best to explain what I want to do. the code below does
> what I want, but it seems needlessly complicated. I figure there is
> probably a nice clean way to do this is less steps but I don't see it:
>
> Essentially, I have a list of all the fields "@all", and I want to produce a
> list of only the fields I'm interested in, and their position in the
> original list
>
> my @all = wq/this that other some junk trash need/;
> my %all;
> my @all{@all} = (0..$#all);
>
> my @interesting = qw/this that need/;
> my %interesting;
> @interesting{@interesting} = delete @all{@interesting};
>
> thanks
> Jay
>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at mail.pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
More information about the Chicago-talk
mailing list