----- Original Message ----- From: "Marco Antonio Valenzuela Escárcega" <[EMAIL PROTECTED]> To: "Shawn" <[EMAIL PROTECTED]> Cc: "drieux" <[EMAIL PROTECTED]>; "begin begin" <[EMAIL PROTECTED]>; "Paul Johnson" <[EMAIL PROTECTED]> Sent: Sunday, June 23, 2002 12:11 AM Subject: Re: Debug and dereferrencing a hash
> On Sat, 2002-06-22 at 21:42, Shawn wrote: > > >>> On Sat, 2002-06-22 at 13:53, Shawn wrote: > > >>>> Is there a reason for this, and is there a way I can see what the > > >>>> actuall values are? The values are passed just fine to the sub routines, > > >>>> I just want my debug log to show that values passed without having to > > >>>> set up a for loop (ie: print %$hash_ref). > > >>>> > > >>>> TIA, > > >>>> Shawn > > >>> > > >>> probably you are trying to use the hash in scalar context, > > >>> > > >>> you should be able to se the values like this: > > >>> > > >>> print "@{ [ values %$hash_ref ] }\n"; > > >> > > >> way Close > > >> > > >> my %hash = (user => 1,pass => 2,thing => 3,ptr => [qw(4 5)],); > > >> > > >> my $hash_ref = \%hash; > > >> > > >> print split(/ /,%$hash_ref ), "\n"; > > >> print "Not Split: ", %$hash_ref, " :\n"; > > >> my @array = %$hash_ref; > > >> print "Array Game: @array :\n"; > > >> > > >> print " Player: @{ [ %$hash_ref ] }\n"; > > >> > > >> generates > > >> > > >> 4/8 > > > > > > > > This is the number of buckets used over the number of buckets. Probably > > > not terribly useful unless you are optimising hashing algorithms. In > > > this case it shows that perl has done a pretty good job with the hash. > > > > > > Can you elaborate more on the 'buckets' Paul, or point me to a doc that explains >it more? All the hash elements should be (are) filled when I dereferrence the hash >in PACKAGEB. So why would I ever see 1/8? > > > > >> Not Split: pass2thing3ptrARRAY(0x6410)user1 : > > >> Array Game: pass 2 thing 3 ptr ARRAY(0x6410) user 1 : > > >> Player: pass 2 thing 3 ptr ARRAY(0x6410) user 1 > > > > Ok, well, I think I am basically doing this (Not Split)... let me give you a >snippet (a very basic one anyway): > > > > MAIN script: > > use PACKAGEA; > > use PACKAGEB; > > $A=PACKAGEA->new; # OBJ A gathers all url params > > $B=PACKAGEB->new; > > print $B->somesub(&make_hash); > > print $B->{DEBUG}; > > exit; > > > > sub make_hash { > > my %hash; > > for('1','2','3','4') { > > $hash{$_}=$A->params($_); > > } > > return(\%hash); > > } > > > > PACKAGEB: > > .... > > sub somesub { > > my $self=shift; > > $self->{DEBUG}.="B::somesub called (line # ".__LINE__.")\n"; > > $self->{SOMEPARAM}=shift; > > $self->{DEBUG}.=" SOMEPARAM: ".%{$self->{SOMEPARAM}}."\n"; > here's the problem: when you try to concatenate the hash to the string > you are evaluating it in scalar context, and that's why it gives you the > number of used buckets > > this should work: > $self->{DEBUG}.=" SOMEPARAM: @{[%{$self->{SOMEPARAM}}]}\n"; Ok, I will agree, this is VERY ugly :-) But it does to exactly what I was looking for. Let me ask this now: Is '%' not ever interpolated into a string as '$' and '@' are? Is that why this whole messy thing exists that I am forced to turn a hash into a referrenced array and then dereferrence it? And, if you (or anyone else) know, how much cpu/ram am I wasting by doing this? This debug setup is only for inhouse r&d, so it will not affect the live version, I am just curious. Thanks, Shawn > > after you dereference the hash, you populate an anonymous array with it, > and then you dereference the array and interpolate it in the string > > its very ugly, but it'll work ;-) > > ... > > } > > .... > > > > The data sets get a bit more complex from here, but that is not an issue for me at >this point. I can print out the referenced arrays and strings fine. It is only the >hashes that I am having issues with... > > > > Again, TIA, > > Shawn > > > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]