Syntax to retrieve $# from de-referenced array

S

sjcampbl

I understand to retrieve the highest array subscript I use the
syntax...

$#MyArray

However, what if the array is a reference held within a greater hash
structure...

%MyHash{MyHashKey} holds a reference to an array

How do I retrieve $# on this?

$#{MyHash{MyHashKey}} doesn't seem to work.
 
A

A. Sinan Unur

(e-mail address removed) wrote in @s1g2000prg.googlegroups.com:
I understand to retrieve the highest array subscript I use the
syntax...

$#MyArray

However, what if the array is a reference held within a greater hash
structure...

%MyHash{MyHashKey} holds a reference to an array

How do I retrieve $# on this?

$#{MyHash{MyHashKey}} doesn't seem to work.

#!/usr/bin/perl

use strict;
use warnings;

my %MyHash = ( MyHashKey => [1, 2, 3] );

print $#{$MyHash{MyHashKey}}, "\n";

__END__

C:\Temp> h
2


--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
J

Jürgen Exner

I understand to retrieve the highest array subscript I use the
syntax...

$#MyArray

Actually $MyArray[-1] maybe more perlish.
However, what if the array is a reference held within a greater hash
structure...

You can still use ....[-1] :)
%MyHash{MyHashKey} holds a reference to an array

How do I retrieve $# on this?

See 'perldoc perlretut' and follow rule 1 in "Using references".

jue
 
T

Tad J McClellan

Jürgen Exner said:
I understand to retrieve the highest array subscript I use the
syntax...

$#MyArray

Actually $MyArray[-1] maybe more perlish.


Except that it does something completely different. :)

What is wanted is the subscript, not the value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,010
Latest member
MerrillEic

Latest Threads

Top