in reply to Re: Looking for exact match in an array
in thread Looking for exact match in an array

Nice reply, but there are a few things I would do differently. Consider this another "[p]ick whichever you like most" post.

# your number 1 uses "if (not ...)" # which is equivalent to "unless (...)" # 4 unless (exists $sheets{$machine_sheetname}) { $sheets{$machine_sheetname} = 1; } # but I'm not really sure why you're checking for existence at all. # just incrementing the value is the simplest approach. # 5 $sheets{$machine_sheetname}++;

Replies are listed 'Best First'.
Re^3: Looking for exact match in an array
by gaal (Parson) on Dec 10, 2004 at 20:35 UTC
    Personally, I like unless almost only in statement modifier position, where the expression is simple. This is a matter of taste and I'm not arguing that this is better. (Well, I'm almost certain to wrinkle my nose at *complex* expressions that start with unless.) So I'd much rather do #2 than #4. You'll notice that I included the existence test only in #1, which was the long form.

    #5 is fine and dandy, and has the additional feature of giving you a count of seen instances. I do this sometimes :) but where what I'm implemented is strictly a set, sometimes I prefer decidedly not to have it, just to make clear that the only information this hash provides is membership. YMMV etc.