finding the last element in a referenced array

From: .rhavin (rhavin_at_shadowtec.de)
Date: 10/05/04


Date: 5 Oct 2004 08:37:38 -0700

i searched the usenet for a while and i wasn't able to find something
useful. perhaps i looked in the wrong places or i am to stupid -
whatever... here's my problem:

i want to access the last elemt of an array... sounds like $#array, i
know, but in my case, the array is stored as a reference in a
construction like this:

$hash{'%1'}{'%2'}=[1,2,3];

i can access the last element by

$hash{'%1'}{'%2'}[2]

cos i know it is the second, but i need a way to access the last
element without knowing whether it is the first, or the zeroth or
whatever.

i tried

$hash{'%1'}{'%2'}[$#hash{'%1'}{'%2'}]

but it doesn't work this way...

anybody willing to help, explain the mystics or simple
answer-pointing?



Relevant Pages

  • Re: <ctype.h> toLower()
    ... that's logic for you - so now anyone who contributes to a Usenet ... > industry when you don't even know what an array is. ... (Of course, your cheap shot ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Comparing two functions. Need review...
    ... > Where is the function prototype? ... then you can assume that his sql_fetch_row returns an array because ... However stupidy you are, DO NOT TOP POST on USENET. ...
    (comp.lang.php)
  • Re: finding the last element in a referenced array
    ... .rhavin wrote: ... > i searched the usenet for a while and i wasn't able to find something ... To access the last element in an array use -1. ...
    (comp.lang.perl.misc)
  • Re: Strange thing about malloc()
    ... > It's absolutely ridiculous to put this on a worldwide USENET posting. ... I've noticed stranger things about c-releases, ... THe array is first declared ... >>When N is odd, the program will work just fine, however when N is even, it ...
    (comp.lang.c)
  • Basic array stuff... Why [0] & [key] and [1] & [value] duplication?
    ... I've been studying this for hours, searching the www & usenet, and ... still can't figure out why 'each' returns an array of four key/value ...
    (comp.lang.php)