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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.