in reply to Defining Arrays

Something like this?
my @ary = map {$_ / 10} (15...94) ;
update: something like my @ary = map { sprintf("%.1f", $_ / 10) } (15...94) ; if you want to limit it to one decimal place.

Replies are listed 'Best First'.
Re: Re: Defining Arrays
by Masem (Monsignor) on May 17, 2001 at 17:12 UTC
    Going one step further to prevent floating point math problems:
    my @ary = map { int ($_ / 10) . '.' . ($_ % 10) } (15..94);

    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

      FYI, I see no advantage to this method whatsoever.

              - tye (but my friends call me "Tye")
        I don't see it happening in this specific case, but in the general case, I would expect that I'll start seeing floating point errors when you do the division, particulary if you got away from multiples of 10, eg, increments of 0.2, 0.5 or so on. Mind you, I don't think this map solution works as cleanly as in this case (thus resorting to a basic for loop)....
        Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain