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; .... }
L*
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.
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
In Section
Seekers of Perl Wisdom