Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: modify list through grep

by calin (Deacon)
on Nov 26, 2006 at 16:46 UTC ( [id://586126]=note: print w/replies, xml ) Need Help??


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

Yes, you're right. My reply was a bit tongue-in-cheek - the OP asked why his grep aliasing example "didn't work" and I resolved to beat it into submission ;)

There's a slight difference though. *m = \@l; aliases the entire array object. The sub {\@_} trick creates a new array object containing scalar elements which are aliased to memberes in @l matching /a/ (in OP's example it contains only one element aliased to the first element in @l - "a").

Replies are listed 'Best First'.
Re^4: modify list through grep
by syntactic (Initiate) on Nov 26, 2006 at 21:30 UTC
    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.
      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        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://586126]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found