in reply to Re: ugly nested if's
in thread ugly nested if's

Just a nitpick: I do not like your statement with the assignment to the hash slice.
@lookup_hash{@list2} = undef;
It'll do exactly what you want, but only in this particular case. It exhibits a lack of elegance: it looks like it's doing something other than what it's really doing. Let me demonstrate what I mean, by assigning a different value:
my @list2 = qw(one two three); my %lookup_hash; @lookup_hash{@list2} = 'foo'; use Data::Dumper; print Dumper \%lookup_hash;
Result:
$VAR1 = { 'three' => undef, 'one' => 'foo', 'two' => undef };
If you were expecting to see "foo" for every value, think again. You are assigning an explicit value (in your code, undef) to the first hash element in the slice, and an implicit undef to all the others.

As for better idioms (IMO)... In this particular case, I'd assign an implied undef for all hash elements, no exceptions:

@lookup_hash{@list2} = ();
In order to assign the same explicit value to all:
@lookup_hash{@list2} = ('foo') x @list2;

--
Thank you. I'll get off my soap box now.

Replies are listed 'Best First'.
Re: Re(2): ugly nested if's (broken idiom)
by dragonchild (Archbishop) on Apr 23, 2004 at 11:36 UTC
    Actually, the idiom I wanted to use was
    undef @lookup_hash{@list};

    But, I've found that it fails for symbolic references living in packages other than the one you're executing in under some builds of Perl. Doing an explicit assignment (either with undef or the empty list) works in all builds I've tried.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose