Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: number of keys and values in a hash

by veerubiji (Sexton)
on Oct 12, 2011 at 10:04 UTC ( [id://930963]=note: print w/replies, xml ) Need Help??


in reply to Re: number of keys and values in a hash
in thread number of keys and values in a hash

i tried like that as you said but i have one doubt

#!/usr/bin/perl use warnings; use strict; use XML::LibXML::Reader; my $file;open $file, 'formal.xml'); my $reader = XML::LibXML::Reader->new( IO => $file ) or die ("unable t +o open file"); while ( $reader->nextElement( 'DATA' ) ) { my $info = $reader->readOuterXml(); $reader->nextElement( 'number' ); my $number = $reader->readInnerXml(); $nums{$number}=$info; print( "num: $number\n" ); print( " datainfo: $info\n" }

it excuting but can i print hash directly not using

print( "num: $number\n" ); print( " datainfo: $info\n"
i tried like this
print %nums;
but it excuting infinity times. and also how to specify input path outside the module.

Replies are listed 'Best First'.
Re^3: number of keys and values in a hash
by pvaldes (Chaplain) on Oct 12, 2011 at 10:58 UTC

    Sigh, I think that your real problem is the lack of a solid basis. I don't want to be rude but it seems that you don't know exactly what are you doing. If you need help to iterate, print a hash or even open a file, the best advice that I can give you is: "Stop now, stop to write code for a while and read some manuals".

    how can i count number of keys in hash can you tel me how to create hash table in my code. how can i iterate all keys in my hash I need to to fill my hash with all keys

    If you open the manual for the function keys (perldoc -f keys) you will have the answer to your first question in the fourth line. If you take a look to the faqs (perldoc perlfaq) you will see that the perlfaq4 cover "How do I process an entire hash?" and "How can I know how many entries are in a hash?"

    Well... just read the manual, we can't do this for you...

Re^3: number of keys and values in a hash
by jethro (Monsignor) on Oct 12, 2011 at 19:59 UTC

    Naturally when you put a print statement inside a loop it prints as often as the loop is executed. And when you have a print statement inside a loop inside another loop, this print statement will be executed much much more often. If you don't want to print so many times, put the print statement AFTER the loop(s).

      thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://930963]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-16 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found