Jenda Krynicky wrote: > From: Steve Bertrand <st...@ibctech.ca> >> Hi all, >> >> I know this is a no-brainer, but I'm drawing a blank after coding all >> day (I'm not a coder by trade). >> >> I'm trying to write a test program for a function I'm accessing from a >> module I wrote years ago, and because I'm over-tired, I can't remember >> how to (or find how to) iterate over the items within an object. >> >> This is literally my test program. The $user object contains a couple >> dozen vars. One of them is shown in a print statement with the expected >> output as a comment. >> >> The following (and numerous variants of it) do not work. How do I >> properly iterate through all of the items in '$user'?: >> >> ---- code below ---- >> >> #!/usr/bin/perl >> >> use warnings; >> use strict; >> use EagleUser; >> >> my $user = EagleUser->new(); >> >> $user->build_inf_user('steveb'); >> >> print "$user->{'login_name'}\n"; # outputs 'steveb' as expected >> >> while ( my ($key, $value) = each($user) ) { > > while ( my ($key, $value) = each(%$user) ) { > >> print "$key => $value\n"; >> } >> >> ---- end code ---- >> >> Cheers, >> >> Steve > > It doesn't matter whether it's an object. It's a hash reference so > you can treat it as such. And since each() expects a hash, not a hash > reference, you have to dereference. That is put a % in front of the > $user.
Thanks Jenda. I'm going to have to really focus on learning about the dereferencing factor, and where/when some of the [${}->] etc need to be, because I don't have a very good grasp on that. Steve
smime.p7s
Description: S/MIME Cryptographic Signature