Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Index number repeating in for loop

by davido (Archbishop)
on Jun 28, 2013 at 22:13 UTC ( #1041359=note: print w/ replies, xml ) Need Help??


in reply to Index number repeating in for loop

...or simply...

print "'F' is at index: $_\n" for grep { $text[$_] eq 'F' } 0 .. $#text;

List::MoreUtils provides a sugary alternative, "indexes":

use List::MoreUtils qw( indexes ); # ... print "'F' is at index: $_\n" for indexes { $_ eq 'F' } @text;

This is a case where I prefer grep because what it's doing isn't unclear or awkward enough to justify the module (imho).


Dave


Comment on Re: Index number repeating in for loop
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-04-20 02:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls