in reply to Re^3: Perl::Improved Volume 0, Number 0
in thread Perl::Improved Volume 0, Number 0

Well, that would be:
$a [$J * ($i - 1) + $j]
as opposed to
$a [($J + 1) * $i + $j]
where $J is the highest second dimensional index. (Which if indices start with 1 happens to be identical to the number of indices).

If indices start at 1, taking a slice till the end of an array can be written as:

$a [5 .. @a]
instead of having to write
$a [5 .. @a - 1]
or to have to use the $#array form:
$a [5 .. $#a]

Replies are listed 'Best First'.
Re^5: Perl::Improved Volume 0, Number 0
by ambrus (Abbot) on Aug 30, 2004 at 17:14 UTC
    If indices start at 1, taking a slice till the end of an array can be written as:

    The good solution for that imo would be to have the .. and ... operators as in ruby, that is, 3..8 means an inclusive range, but 3...8 means a range including 3 but not including 8.

    Update: I say this because I've never seen any good example of using $#{} other than a range ending in it.

      Better still, have .. do some magic when unary to go right to the end of the array being indexed:

      $a[ 5 .. ]; # Equivilent to $a[ 5 .. $#a ]

      Though I have no idea how hard that would be to add, or what compatibility issues come up.

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

        I may be mistaken (I have a hard time following all the developments and keeping the status quo straight), but to my knowledge, that's supposed to work Perl6.

        Makeshifts last the longest.

        That would be difficult, because 5..$#a is not always used in such a context (subscripting). It is used in other code like @data[sort { $data[$a]<=>$data[$b] } 0..$#data] where it would be difficult to derive the endpoint automatically.

        Btw I think perl6 will have infinite ranges, which is a good idea.