in reply to Last Element of Hash

I was thinking something like:

my @elements = ( keys %hash ); foreach (@elements){ if ( $_ eq $elements[-1] ){ #Do something to last element }else{ #Do something to an item in element } }

To me, it's easier to see it that way... I'm still rather "young" on Perl :-)
caveat: above will give warnings if @elements is full of numbers...

LR

Update: Changed @elements[-1] to $elements[-1]

Whip me, Beat me, Make me use Y-ModemG.

Replies are listed 'Best First'.
Re: Re: Last Element of Hash
by bart (Canon) on Sep 26, 2003 at 13:26 UTC
    caveat: above will give warnings if @elements is full of numbers...
    No it won't. You can always use a number as a string without any warning. The reverse isn't always true.

    And besides, here, the elements are originally hash keys. Hash keys are always strings.

      Thanks for the clarification... I still get confused sometimes over the little details, but I'm slowly getting the hang of it :-)

      LR

      Whip me, Beat me, Make me use Y-ModemG.