in reply to Using 'sort' to emulate SQL's 'select'...

Why are you using a sort to get the keys? And why the pluses? Pluses are usually used to distinguish between a block of code and a hash, but in this case you don't need the '+' because it'll be considered an anonymous hash anyways...

my %HoH = ( 1 => { foo => 'bar', baz => 'bletch' }, 2 => { foo => 'bar2', baz => 'bletch2' }, ); my @fookeys = grep { $HoH{$_}{foo} eq 'bar2' } keys %HoH; # @fookeys is now 2


ar0n ]

Replies are listed 'Best First'.
Re: (ar0n) Re: Using 'sort' to emulate SQL's 'select'...
by deprecated (Priest) on Apr 22, 2001 at 19:51 UTC
    from perldoc perlref:
    For example, if you wanted a function to make a new hash and return a reference to it, you have these options: sub hashem { { @_ } } # silently wrong sub hashem { +{ @_ } } # ok sub hashem { return { @_ } } # ok On the other hand, if you want the other meaning, you can do this: sub showem { { @_ } } # ambiguous (currently o +k, but may change) sub showem { {; @_ } } # ok sub showem { { return @_ } } # ok The leading +{ and {; always serve to disambiguate the expression to mean either the HASH reference, or the BLOCK.
    I use HoH's a lot in my code, so I try to make absolutely sure my hashes are as disambiguated as they can be.

    --
    Laziness, Impatience, Hubris, and Generosity.