Re: Perl question: array member of referenced hash

2009-10-24 Thread Gabor Szabo
On Sat, Oct 24, 2009 at 11:25 PM, Shachar Shemesh wrote: > Let me try to summarize what I understood from your excellent explanation: if that works for you :-) > > All that is left is understanding why the round braces around the whole > expression. Oh, the syntax of foreach has those parenthe

Re: Perl question: array member of referenced hash

2009-10-24 Thread Shachar Shemesh
Gabor Szabo wrote: err, I don't think that "casting" is the right word to use here. What {} does here is disambiguates the expression. Let me try to summarize what I understood from your excellent explanation: Putting a modifier in front of a reference dereference it to the right type ($ for

Re: Perl question: array member of referenced hash

2009-10-24 Thread Gabor Szabo
2009/10/24 Shachar Shemesh : > Noam Rathaus wrote: > > Shachar, > > { } in Perl are casting when they surround a value > And the second set of { } around the 'a' mean variable of Hash > > > > > Grumble grumble grumble not surprised as this is one of the funky places of Perl 5. > > Okay, I'm s

Re: Perl question: array member of referenced hash

2009-10-24 Thread Shachar Shemesh
Noam Rathaus wrote: Shachar, { } in Perl are casting when they surround a value And the second set of { } around the 'a' mean variable of Hash Grumble grumble grumble Okay, I'm sorry for being difficult. I really couldn't find the answer in the Perl documentation. I understand the

Re: Perl question: array member of referenced hash

2009-10-24 Thread Noam Rathaus
Shachar, { } in Perl are casting when they surround a value And the second set of { } around the 'a' mean variable of Hash 2009/10/24 Shachar Shemesh : > Dov Grobgeld wrote: > > Noam beat me to it, but here's perl solution without additional variables: > > #!/usr/bin/perl > > %hash = (a=>['moo',

Re: Perl question: array member of referenced hash

2009-10-24 Thread Shachar Shemesh
Dov Grobgeld wrote: Noam beat me to it, but here's perl solution without additional variables: #!/usr/bin/perl %hash = (a=>['moo','goo','woo'], foo=>3, baz=>5); $ref = \%hash; foreach my $elem (@{$ref->{a}}) Hi Dov, Yes, it works. Now can you, please, explain to me why? Wha

Re: Perl question: array member of referenced hash

2009-10-24 Thread Dov Grobgeld
Noam beat me to it, but here's perl solution without additional variables: #!/usr/bin/perl %hash = (a=>['moo','goo','woo'], foo=>3, baz=>5); $ref = \%hash; foreach my $elem (@{$ref->{a}}) { print "$elem\n"; } Regards, Dov 2009/10/24 Shachar Shemesh > Hi all, > > $ref i

Re: Perl question: array member of referenced hash

2009-10-24 Thread Noam Rathaus
Sorry a mistake... foreach my $ptrelem (keys %hash) { Should be foreach my $key (keys %hash) { my $ptritem = %hash->{$key}; On Sat, Oct 24, 2009 at 7:55 PM, Noam Rathaus wrote: > Hi Shachar, > > First you can always use Data::Dumper: > use Data::Dumper; > print Dumper($ref); > > To make sure

Re: Perl question: array member of referenced hash

2009-10-24 Thread Noam Rathaus
Hi Shachar, First you can always use Data::Dumper: use Data::Dumper; print Dumper($ref); To make sure that the data is stored correctly. In regard to your question: my $ref; my %hash = %{$ref}; foreach my $ptrelem (keys %hash) { my @array = @{$ptrelem}; foreach my $item (@array) { print $it

Perl question: array member of referenced hash

2009-10-24 Thread Shachar Shemesh
Hi all, $ref is a reference to a hash. Hash contains a component called "a" which is an array. I would like to iterate all elements of said array. I would like to do something along the lines of: foreach my $elem @%$ref{a} { print "$elem\n"; } Which, I think it clear, does not work. I also