Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: loop array excluding some elements

by Eily (Prior)
on Mar 08, 2018 at 17:45 UTC ( #1210522=note: print w/replies, xml ) Need Help??


in reply to loop array excluding some elements

grep in list context (eg, used in a for) will create a new list by selecting elements in its input that match a condition. IE:

foreach (grep { $_ != 0 } @SlectedColumns[1..$NrCoumns]) { # Only non zero elements here }

Edit: and if your input is only numbers, and the content of the loop is just one EXPR, you can even write: print "I'm priting $_!\n" for grep $_, @SlectedColumns[1..$NrCoumns];

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1210522]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2018-06-25 01:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (126 votes). Check out past polls.

    Notices?