The stupid question is the question not asked PerlMonks

### Re^2: Determine steps between two numbers

by grizzley (Chaplain)
 on Sep 05, 2012 at 13:32 UTC ( #991852=note: print w/replies, xml ) Need Help??

in reply to Re: Determine steps between two numbers
in thread Determine steps between two numbers

IMHO in such case the variable name should be changed from 'increment' to 'decrement'. Or better - change algorithm to more intuitive:
```my \$increment = (\$second - \$first) / (\$steps - 1);
...
push @array, \$first += \$increment;
And one-line @array generator as alternative:

my @array = map { \$first + \$increment * \$_ } 0 .. \$steps - 1;

Replies are listed 'Best First'.
Re^3: Determine steps between two numbers
by thmsdrew (Scribe) on Sep 05, 2012 at 13:47 UTC

Thanks. I transferred this over from my Java implementation of it and didn't quite get it right, so I did some stuff to make it work. You helped me get it back to what it was originally. Not too confident in the one-line generator you have there, but it'd be a nice touch anyway.

Not too confident in the one-line generator you have there, but it'd be a nice touch anyway.
Why? Don't you trust mathematics?

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

I trust the math of it. It's not that I'm not confident that grizzley's solution is mathematically sound. Rather, I'm not confident in my own ability to fully understand that use of map, especially if I were to stop thinking about this and come back to it later. I also don't really see the need.

Create A New User
Node Status?
node history
Node Type: note [id://991852]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2017-06-25 09:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many monitors do you use while coding?

Results (565 votes). Check out past polls.