in reply to Re: greping thru a hash of arrays
in thread greping thru a hash of arrays

Thanks, that works. But why?

Replies are listed 'Best First'.
Re^3: greping thru a hash of arrays
by linuxer (Curate) on May 20, 2008 at 21:15 UTC
    grep /$_/, [ @{$tbl{$i}} ]

    means:
    Dereference the array-Ref in $tbl{$i}, make a reference to an anonymous array ( [ ] ) from the resulting list and grep through a list with a single item: the single reference to the anonymous array.

    @tbl{$i} is btw. wrong, see this example :
    $perl perl use strict; use warnings; my %hash; $hash{a} = [ 1,2 ]; print "@hash{a}", $/; Scalar value @hash{a} better written as $hash{a} at - line 7.

    edit: several updates/corrections due to some misleading thoughts while typing too fast

Re^3: greping thru a hash of arrays
by pc88mxer (Vicar) on May 20, 2008 at 21:19 UTC
    There were a few errors. As linuxer pointed out, the second argument to grep should not be an array-ref. The second through last arguments are the list of items to grep through.

    Also, instead of @tbl{$i} you want to use @{$tbl{$i}}.