in reply to Re^3: modify list through grep
in thread modify list through grep

thanks, this would be a solution for me, unfortunately the code with sub still gives "a b c "
Extended version of the code I'm trying to get to work
foreach $p ( @patterns ) { if ( ??? grep /$p/, @values ) { modify the matching list value; } else { push @values, "strings $pattern"; } }
For the modification part I can use grep again and modify the value through $_, but then I call expensive grep twice. If I could save a reference (alias?) into @values in the if condition statement I can have a lighter code.

Replies are listed 'Best First'.
Re^5: modify list through grep (slice)
by tye (Sage) on Nov 27, 2006 at 06:19 UTC
    for my $p ( @patterns ) { my $found= 0; for my $last ( ( grep /$p/, @values )[-1] ) { $last .= '.'; # whatever mod you want $found= 1; } push @values, "string $p" if ! $found; }

    - tye