in reply to Re^2: adding an index column to a csv data file
in thread adding an index column to a multi-array derived from a csv data file

You could generalize this a bit further and eliminate the  $i variable (one less thing to worry about):

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @multi_array = ([ 99, 88 ], [ 77, 66 ], [ 55, 44 ], ); ;; push @{ $multi_array[$_] }, $_ for 0 .. $#multi_array; dd \@multi_array; " [[99, 88, 0], [77, 66, 1], [55, 44, 2]]
but I'm not sure this is really an improvement WRT clarity and maintainability! unshift or splice could be used to stuff the new element at other offsets in the array. The "pure index" version is even more obscure:
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @multi_array = ([ 99, 88 ], [ 77, 66 ], [ 55, 44 ], ); ;; $multi_array[$_][ @{$multi_array[$_]} ] = $_ for 0 .. $#multi_array; dd \@multi_array; " [[99, 88, 0], [77, 66, 1], [55, 44, 2]]


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^4: adding an index column to a csv data file
by ng0177 (Acolyte) on Jun 02, 2019 at 17:44 UTC

    The $i less variant is good for learning.