J
J
jslby2015-07-11 18:14:53
Perl
jslby, 2015-07-11 18:14:53

How to get a specific element of an array in Perl?

The data is added to the array next. way:

my %thisData = (login => $thisName, pass => $thisPass);
push(@series, \%thisData);

I'm trying to iterate in a loop:
foreach my $el (@series){
  print %el{'login'};
}

But this design doesn't work.
Ideally, I want to get an array of hashes, and iterate over it, with the ability to get the first, second, and third value from the hash. How is this possible?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
targumon, 2015-07-11
@targumon

$el is a hash reference. It must be dereferenced before accessing the hash itself:

foreach my $el (@series){
  print $el->{'login'};
}

V
Vladimir, 2015-07-11
@rostel

perl arrays do not have named keys
use hashes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question