On Fri, Mar 11, 2005 at 04:42:14PM -0800, Wagner, David --- Senior Programmer Analyst --- WGO wrote: > Peter Rabbitson wrote: > > I've been writing a failry complicated data collector with structures > > as deep as 7 levels, and everything worked very nice for me, until I > > started cleaning the subroutine interfaces, so they would pass > > references back and forth instead of working on global vars. The > > following is a sample code: > > > > use warnings; > > use strict; > > > > my %batches = (); > > > > my $current_batch = 'abc'; > > > > > > push @{$batches{$current_batch}{transactions}}, { trans_num => 'a', > > reference => 'b', > > card_num => 'c' > > }; > > > > _NASTY_SUB (\%{$batches{$current_batch}}); > > > > exit; > > > > sub _NASTY_SUB { > > > > my ($hashref) = @_; > > > > foreach my $transaction > > (@{$batches{$current_batch}{transactions}}) { > > > > print join (' * ', keys %{$transaction}); > > print "\n-------\n"; > > } > > > > > > foreach my $transaction (@{$hashref}{transactions}) { > > > > print join (' * ', keys %{$transaction}); > > print "\n-------\n"; > > } > To derefence this setup should be something like: > foreach my $transaction (@{$hashref->{transactions}}) { > > print join (' * ', keys %{$transaction}); > print "\n-------\n"; > } > which prints out: > reference * card_num * trans_num > ------- > > No Errors. You are passing the Reference as you should to the > subroutine. So to derefence you would use -> or you could do : > @{$$hashref{transactions}} > which has the $$ indicating derefencing. > > Myself, it seems much easier to use -> but that is my prefernce. > > Wags ;) > > > } > > > > > > The first foreach in the sub, while using a variable from the main > > scope works like a charm. The second foreach, while working on the > > reference, gives me a warning on something that google only says will > > be removed as of perl 5.10. What is the actual meaning of > > pseudo-hashes? To me both foreach statements look identical... > > > > > > Peter > > >
Makes sense... I see where I missed a dereference. I actually was never able to grasp dereferencing using ->, it doesn't follow my logic in a sense (or very possible I haven't seen any good examples of it). Could you rewrite the following dereferencing using -> (not a joke, it's a real life example, I am getting a hash slice so to speak to save myself tons of dereferencing down the road) my %cards = %{clone (\%{$sources{${$batch_ref}{by_method}}{card_def}} )}; Thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>