Bowie Bailey wrote:

> ukhas jean wrote:
> 
>>#Here I was expecting variable interpolation to occur, but the o/p
>>comes same as in 
>>print '%hash'; Why is Perl behaving likes this??
> 
> Perl doesn't interpolate hashes like this.

Correct - Perl only interpolates scalars and arrays in a string.

>>Prgrm.2:-
>>
>>%hash = (a=>111,
>>               b=>222,
>>               );
>>print %hash . "\n";
>># I purposefully put a newline character here, but I am unable to
>>comprehend the o/p #Here O/p comes as:-
>>#2/8
>>#I am at my wits end as to what does this figure indicate?? Can any
>>of u gurus help me plz?? #i added one more element to the hash,
>>c=>333, so that the hash became as follows:- #%hash = (a=>111,
>>  b=>222,
>>  c=>333);
>>#But now the O/p comes as:-
>>#3/8
> 
> Once again, Perl will not do any auto-magical printing of hashes, you
> have to do it yourself.  The '3' here apparently refers to the number
> of hash elements.  I'm not sure about the 8.  It's probably in the
> docs somewhere, but I'm too lazy to look it up.

perldata man page:

        ...

    If you evaluate a hash in scalar context, it returns false if the hash is
    empty. If there are any key/value pairs, it returns true; more precisely,
    the value returned is a string consisting of the number of used buckets and
    the number of allocated buckets, separated by a slash. This is pretty much
    useful only to find out whether Perl's internal hashing algorithm is
    performing poorly on your data set. For example, you stick 10,000 things in
    a hash, but evaluating %HASH in scalar context reveals "1/16", which means
    only one out of sixteen buckets has been touched, and presumably contains
    all 10,000 of your items. This isn't supposed to happen.

>>Kindly forgive me if these are stupid questions, but I have nowhere
>>else to turn to for help. Hoping you will kindly oblige. 
>>Any hints/answers/suggestions are utmost welcome.
> 
> 
> You'll need to print the hash manually like this:
> 
> for $hk (keys %hash) {
>     print "$hk: $hash{$hk}\n";
> }

Or use Data:Dumper.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to