in reply to Grep and AoH references

Grep wants an array for its second argument. Dereference your AoHref:
my $newAoH = [grep { !($_->{'name'} eq "fred") } @$AoHref];
Update: I was too hasty and only fixed the dereference problem. Obviously, to create a new AoH, you have to actually create the reference. So I've put the brackets on the expression.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Grep and AoH references
by de-merphq (Beadle) on Dec 30, 2004 at 16:49 UTC

    Actually grep want a list following its first argument. The reason the code doesnt throw a wobbly is that a reference to an array is a list of one element (the reference). By dereferencing $AoHref you get a different list, that being the contents of the array. A subtle but important distinction (that lots of folks around here love to harp on about, like me :-)

    Also the code as posted is wrong. Grep returns a list, so if you assign to a scalar like you are you get the count of objects that passed the filter test, not the list of objects. The code should look like my @grepped=grep ...

    ---
    alter ego of demerphq
Re^2: Grep and AoH references
by bradcathey (Prior) on Dec 30, 2004 at 16:50 UTC

    I tried that but Data::Dumper returned "2".


    —Brad
    "Don't ever take a fence down until you know the reason it was put up." G. K. Chesterton