I did not follow the link, so I don't know what you've tried. What you are creating there is an array of array references (AoA). To access the "fileNNN" part, you have to first select the element you want of the top level array (in this case the last element, aka -1), then you select the element of the second level array (the first element, ie. 0):
use warnings; use strict; my @stash; while (<DATA>){ chomp; my($col0, $col1, $col2, $col3) = split ","; push @stash, [$col0, $col1, $col2, $col3]; } print "$stash[-1]->[0]\n"; __DATA__ file706,010390010010,doc_01,paragraph,11 file707,010390010010,doc_01,paragraph,12 file708,010390010010,doc_01,paragraph,09 file710,010390010010,doc_01,paragraph,10 file711,010390010010,doc_01,paragraph,13 file712,010390010010,doc_01,paragraph,11 file713,010390010010,doc_01,paragraph,12 file714,010390010010,doc_01,paragraph,09 file715,010390010010,doc_01,paragraph,10 file716,010390010010,doc_01,paragraph,13 file717,010390010010,doc_01,paragraph,11 file718,010390010010,doc_01,paragraph,12 file719,010390010010,doc_01,paragraph,09 file720,010390010010,doc_01,paragraph,10 file721,010390010010,doc_01,paragraph,11 file722,010390010010,doc_01,paragraph,12 file723,010390010010,doc_01,paragraph,11 file725,010390010010,doc_01,paragraph,12 file726,010390010010,doc_01,paragraph,11 file727,010390010010,doc_01,paragraph,12 file728,010390010010,doc_01,paragraph,11 file729,010390010010,doc_01,paragraph,12 file730,010390010010,doc_01,paragraph,12
Output:
file730
Update: Note that you can shorten your code quite a bit while at the same time eliminating unnecessary variable assignments by expanding split inside of the aref you're pushing. This is of course if you aren't using those individual variables elsewhere in the code:
while (<DATA>){ chomp; push @stash, [split /,/]; }
In reply to Re: Last position of array
by stevieb
in thread Last position of array
by EBK
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |