[ABE.pm] Accessing data in an array?

Ricardo SIGNES rjbs-perl-abe at lists.manxome.org
Mon Nov 29 17:24:49 CST 2004


* Faber Fedor <faber at linuxnj.com> [2004-11-29T18:17:14]
> my @indices = ( { index=>"r1", weight=>"r1weight", cap=>"r1_mkt"}
>                 { index=>"r2", weight=>"r2weight", cap=>"r2_mkt"}
>                 { index=>"r3", weight=>"r3weight", cap=>"r3_mkt"}
>                 { index=>"rm", weight=>"rmweight", cap=>"rm_mkt"  }
>         );
> 
> What I've been doing is looping through them so I could get at the data
> like this:
> 
> for(@indices) {
>     print $_->{index} . "\t" . $_->{weight} . "\n";
> }
> 
> but now I need to access each internal reference(?) without looping.
> IOW, if I have $var = "r3", how do I access the array such that
> $indices->{weight}="r3weight"?

This question doesn't seem to make sense to me.  If @indices is an
array, you can never dereference it as a hash, as you are doing when you
say $indices->{weight}.

When you say C< for (@indices) > you are getting $_ set, each iteration,
to the reference to a hash contained within the next element of the
array @indices.

Do you mean that you need to know the numerical index of the current
iteration?  I guess I need you to ask the question differently; maybe
give a real-world example?

-- 
rjbs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/archives/abe-pm/attachments/20041129/0e185b57/attachment.bin


More information about the ABE-pm mailing list