I am new to Perl. I am trying to identify how to print the size of hash of array. Below are snippets of my code.
my %map = (); // Initialization
while ($line = <>) {
chomp($line);
// Logic to split the $line
push( @{$map{$first_var}}, $rest );
}
// Print the amp
foreach my $value (sort keys %map) {
print "$value: @{$map{$value}}\n";
}
On printing I get output in below format
valA: (num1 num2 num3 num4)
valb: (num2 num4)
valC: (num1 num3 num4)
I wish to identify the how many elements are associated with each key (valA, valB,valc).
I tried: print "Number of nodes in the facility : scalar @{$map{$facility1}}\n";
However it gives out as
valA: scalar (num1 num2 num3 num4)
valb: scalar (num2 num4)
valC: scalar (num1 num3 num4)
I wish the output to show 4, 2, 3 for valA, valB,valC respectively. I maybe misunderstanding but scalar provides length of array.
Thanks
//isn't a comment inperl. Your code cannot work.