Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keys (array of hashes)

Status
Not open for further replies.

vvv

Programmer
Jan 11, 2001
7
0
0
KR
I have array of hashes
$array[0]{in}=
$array[1]{in}=
$array[2]{in}=
$array[0]{out}=
$array[1]{out}=
$array[2]{out}=

and want to do something like

foreach $key ( keys($aaray[0]) ) {lalala}

but keys require explicitly %HASH
i've tried to make %temp=$array{0}; and then keys(%temp)
but it doesn't works 8_(
someone help?
 
I've solved the problem

by setting %temp=%{$array[0]};

 
it's all very touchy syntax.

ok... each element of the array is a reference to a hash, so there is hash reference at:[tt]
$array[0][/tt]

and there's a hash:[tt]
%{$array[0]}[/tt]

and a hash element:[tt]
${$array[0]}{KEY}[/tt]

so it's like every time you would write the name of a hash variable(not any of the '%'s or '$'s.), you write out '{$array[0]}'. then you make sure the other characters are all well placed.
to assign it to a temporary array, you'd do:[tt]
my %temp = %$array[0];[/tt]


another syntax is with '->', and would go:
$array[0] (hash ref)
$array[0]->{KEY} (hash element)
this is easier to keep track of, but a little harder on the grasping conceptually part (in my opinion). "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top