Print dereferenced hash of arrays keys and values

D

Derek Basch

Why do I get a syntax error on this one:

for my $value_resp ( keys %$reactivate_account_hash_ref ) {
print "$value_resp: @{ %$reactivate_account_hash_ref{$value_resp}
}\n";
}

Yes, I read the perldocs....No, I still don't get it.

Thanks,
Derek Basch
 
M

Matt Garrish

Derek Basch said:
Why do I get a syntax error on this one:

for my $value_resp ( keys %$reactivate_account_hash_ref ) {

Keys are not values. You should really try and name your variables better.
print "$value_resp: @{ %$reactivate_account_hash_ref{$value_resp}

So you normally access the values of a hash by prepending a '%'? You
obviously haven't looked very hard at the docs.

Think $href->{$key} and then go back to perlref.

Matt
 
T

Tad McClellan

Derek Basch said:
Why do I get a syntax error on this one:

for my $value_resp ( keys %$reactivate_account_hash_ref ) {
print "$value_resp: @{ %$reactivate_account_hash_ref{$value_resp}
}\n";
}


Because you have not dereferenced the reference:

print "$value_resp: @{ $reactivate_account_hash_ref->{$value_resp} }\n";
or
print "$value_resp: @{ ${$reactivate_account_hash_ref}{$value_resp} }\n";

Yes, I read the perldocs....


You have read over 2000 pages? Wow!

You only need to read the _right_ 8 pages, namely:

perldoc perlreftut
 
D

Derek Basch

Thanks everyone,

Darn, I thought that $$ is what I needed to do. I come from the python
world and keeping my scalars straight is a new way of thinking for me.

However, you Perl guys crack me up. You all seem to love fighting with
each other......ALOT!

Thanks,
Derek Basch
 
P

Priit Randla

Derek said:
Why do I get a syntax error on this one:

for my $value_resp ( keys %$reactivate_account_hash_ref ) {
print "$value_resp: @{ %$reactivate_account_hash_ref{$value_resp} }\n";
}
Because %$reactivate_account_hash_ref{$value_resp} isn't an array
reference. Try $reactivate_account_hash_ref->{$value_resp} instead.
Yes, I read the perldocs....No, I still don't get it.

Thanks,
Derek Basch
Priit
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top