in reply to number of keys and values in a hash

Updated: sorry the former was duplicated, deleted now:

normally the number of keys = number of values, if a value is missing is filled automatically, if a value is undef is not printed, but you still can call it. If you need to discard the null values you can always add a test or if-block

Replies are listed 'Best First'.
Re^2: number of keys and values in a hash
by veerubiji (Sexton) on Oct 11, 2011 at 14:47 UTC
    hi Its not working, it giving only one number is there but i have 148 numbers.can you tel me how to create hash table in my code.
      well, of course you will need to create and fill a hash first with the desired part of your data. The code tells you exactly what you have: my %nums =( "$number", $info) is a hash with one element only, a single pair key-value. You need to iterate between all keys and all values

        Some extra notes about your code:

        while (my ($keys, $values) = each %nums) {

        is probably a little more readable than

        while ((my $keys, my $values) = each (%nums)) {

        and you could prefer also to use

        open my $file, 'formal.xml'; instead: my $file;open $file, 'formal.xml');

        and print "num: $number\n"; instead: print( "num: $number\n" );

        Hi, exactly what i am thinking is i need to fill my hash with more number of elements. now in the above code i have only one element in hash so its displaying one key.i need to iterate all keys and vaues in my hash.can you help how can i iterate all keys in my hash.