Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: loop array excluding some elements

by Discipulus (Monsignor)
on Mar 08, 2018 at 18:15 UTC ( #1210524=note: print w/replies, xml ) Need Help??

in reply to loop array excluding some elements

Hello IB2017,

you are looking for wisdom, not for elegance! ;=)

Elegance can be your enemy: better looking for efficiency and readability.

You already received a wise answer by Eily++ about grep

If your do_something is short as print you can consider also the unless postscript form:

foreach my $ele (@SlectedColumns[1..$NrCoumns]) { do_something unless $ele == 0; }

It's an handy and readable syntax.

If the loop is complex and actions are more, something very similar to your example is a wise form to express some logic: a good principle exit loop early

foreach my $ele(@SlectedColumns[1..$NrCoumns]) { # exit soon next if $ele == 0; next unless defined $ele; .... }


There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2018-06-18 13:53 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (109 votes). Check out past polls.