Having stumbled acros a few errors over the week, I realised, it was because i had failed to understand how the FOR command compared to FOREACH worked on an array of hashes, this also brought to light the ways in which you can de-reference a hash.
So my question is which is better, which is faster or does it not matter.
for my examples my @array = "An array of hash references"
1st example
2nd example
3rd example
my understanding is that becasue PERL see's []{} it automatically de-references the hash.
is that better or quicker and is it ok to de-reference a hash using double $$, rather than ->.
is there a "standard" way of doing this or is it down to preference.
cheers,
1DMF
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
So my question is which is better, which is faster or does it not matter.
for my examples my @array = "An array of hash references"
1st example
Code:
foreach my $hashref (@array){
print $$hashref{'key1'};
}
Code:
foreach my $hashref (@array){
print $hashref->{'key1'};
}
Code:
for(my $x=0; $x<=$#array; $x++){
print $array[$x]{'key1'};
}
my understanding is that becasue PERL see's []{} it automatically de-references the hash.
is that better or quicker and is it ok to de-reference a hash using double $$, rather than ->.
is there a "standard" way of doing this or is it down to preference.
cheers,
1DMF
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.