Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: lsearch for perl?

by matt.tovey (Beadle)
on Dec 06, 2005 at 08:52 UTC ( [id://514369]=note: print w/replies, xml ) Need Help??


in reply to Re: lsearch for perl?
in thread lsearch for perl?

Thanks to all for your replies - they were all very helpful.

Things like this

@list = grep { $item ne $_ } @list;
aren't in the man-page, and got me thinking. This however:
my ($index) = grep { $item eq $list[$_] } 0..$#list; splice(@list, $index, 1) if defined $index;
was a real satori, Keanu-Reeves-like "Whoah!!" moment for me. The idea of using grep on a list without naming _that_ list as the argument to grep would never have occurred to me. Guess I was stuck in Unix grep thinking!

Feeling quite humbled.

Replies are listed 'Best First'.
Re^3: lsearch for perl?
by ikegami (Patriarch) on Dec 06, 2005 at 15:33 UTC
    Things like this aren't in the man-page

    grep accepts any code in the block. It doesn't have to be a regex. grep is useful for filtering out items from a list, while map is useful for transforming a list.

    The idea of using grep on a list without naming _that_ list as the argument to grep would never have occurred to me.

    It's an concept I picked up on PerlMonks too :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-19 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found