in reply to Re: comparison with bitwise operators
in thread comparison with bitwise operators

> my %vals = map {$_ => 1} 2, 3;
> if (exists $vals{$var}) {
>     print "in list\n";
> }

if you wanna test with exists hash-slices are shorter! :)

my %vals; @vals{2,3}=();

but need a separate step for declaration! :(

UPDATE: why do you check with exists anyway?

Cheers Rolf

Replies are listed 'Best First'.
Re^3: comparison with bitwise operators
by toolic (Bishop) on Jan 14, 2011 at 14:11 UTC
    why do you check with exists anyway?
    Out of habit. I consider it defensive programming. In this small example, there is no need to use exists because I have clearly set the values of all keys to 1, which is defined and true, as opposed to undef or 0.

    I also kinda like how it reads.

    If you can convince me there is a significant penalty (performance/memory/etc.) for using exists, then I may consider changing my habit.