Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: the '..' operator and decreasing values

by ikegami (Patriarch)
on Mar 04, 2005 at 22:27 UTC ( [id://436784]=note: print w/replies, xml ) Need Help??


in reply to the '..' operator and decreasing values

.. always counts up. I don't know why, but this workaround will do the trick:

for ( 0 .. 10 ) { my $i = 10 - $_; # do something }

Replies are listed 'Best First'.
Re^2: the '..' operator and decreasing values
by merlyn (Sage) on Mar 04, 2005 at 22:31 UTC

      Let's hope the list isn't too long. for (0..x) is evaluated lazily, but I doubt that for (reverse x..0) is as well.

      On second thought, that would rarely matter.

      Does this create a list all at once so that it can reverse it as opposed ikegami's solution which creates only one value at a time? I ask because I honestly don't know.

      Update: Yarr...that's what I get for not refreshing.

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found