ukhas jean wrote:
> Hello Professors,
>
> I am pleased with the wonderful replies that u all have given to me
> and I really appreciate the help that u all are providing even to a
> beginner like me. I am hoping if someone can help me with two queries
> of mine. I have listed them below:-
>
> Prgrm. 1:-
>
> %hash = (a=>111,
> b=>222,
> );
> print "%hash";
> #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.
> 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.
> 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";
}
--
Bowie
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs