On 05/15/2018 04:34 PM, ToddAndMargo wrote:
On 05/15/2018 03:49 PM, Larry Wall wrote:
On Tue, May 15, 2018 at 03:31:07PM -0700, ToddAndMargo wrote:
: Hi All,
:
: This seems like a trivial question, but I really adore
: the "for" loops.  Is there a way to do the backwards?
: In other words, start at the end of the array and loop
: to the beginning?  Does the "next" and "last" work in
: this?

Just use the reverse method:

     > my @foo = <a b c>;
     [a b c]
     > for @foo.reverse { .say }
     c
     b
     a

or (as in Perl 5) the reverse function:

     > for reverse @foo { .say }
     c
     b
     a

and yes, "next" and "last" work for those loops too, since they are
controlled by the "for", not by the expression you feed to the "for".

Larry


Hi Larry,

Awesome.  I just copied your response down into my "loops"
keeper file.

I use loops and loops with split "a lot".

Thank you!

-T


It is annoying when I read something back from Linux
and they use a <nil> at the start and stop of a
string (the Secondary Clipboard for instance).

But I just use `if not $line {next}` to jump over it.

-T

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to