J
Justin C
I was trying to count the number of elements in a hash, I realise that
the code below is not the way to do it, I've got that bit sorted now,
what I want to know is how I got the output I did.
Here is the code:
#!/usr/bin/perl
use warnings ;
use strict ;
my %hash = (
"mick" => "jagger",
"brian" => "jones",
"keith" => "richards",
"charlie" => "watts",
"bill" => "wyman",
"rolling" => "stones"
) ;
# my $n_items = scalar ( keys ( %hash ) ) ;
# print $n_items, "\n" ;
print scalar ( %hash ), "\n" ;
# end of code
The output, when this is run, is:
4/8
Where does that output come from?
BTW, I'm counting hash elements: my $n_items = scalar( keys( %hash)); now.
Justin.
the code below is not the way to do it, I've got that bit sorted now,
what I want to know is how I got the output I did.
Here is the code:
#!/usr/bin/perl
use warnings ;
use strict ;
my %hash = (
"mick" => "jagger",
"brian" => "jones",
"keith" => "richards",
"charlie" => "watts",
"bill" => "wyman",
"rolling" => "stones"
) ;
# my $n_items = scalar ( keys ( %hash ) ) ;
# print $n_items, "\n" ;
print scalar ( %hash ), "\n" ;
# end of code
The output, when this is run, is:
4/8
Where does that output come from?
BTW, I'm counting hash elements: my $n_items = scalar( keys( %hash)); now.
Justin.