Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: foreach my $question (@perlmonks){}

by muba (Priest)
on Jun 19, 2012 at 10:27 UTC ( #977015=note: print w/ replies, xml ) Need Help??


in reply to Re^2: foreach my $question (@perlmonks){}
in thread foreach loop not retrieving all data.

But that's not what the code says... Walk through it with me.

my @trips= $p->findnodes( '//table[@id="tblFYCXML_Itin"]'); # So there's exactly one table with that id. # So @trips contains now exactly one node, that node being that one ta +ble. # You still with me? # If not, try it: print "There is/are ", scalar(@trips), " nodes in \@trips.\n";

Okay. And then:

foreach my $trip (@trips){

You see it? Look at that line again. See it now? Look again until you do.

For each element of @trips, an array of which we just established that it has exactly one element, anyway, so for each element of that set of one element,, you want to do something. And you get a result like it runs the loop only exactly one time. Hmm, boggles the mind, don't it :)

If, at this point, you still really need another clue? Try finding those nodes that you want to loop over, and loop over them, instead of trying to loop over something that you know only occurs once.


Comment on Re^3: foreach my $question (@perlmonks){}
Select or Download Code
Re^4: foreach my $question (@perlmonks){}
by marcoss (Novice) on Jun 19, 2012 at 10:54 UTC

    Ok!!, got it... it's working now. I replaced the table for the nodes that are repeated and contain the info I need. I thought the array line was ok, that's why I've been wasting time with the foreach. Thank you so much!!!

    marcos

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2014-07-26 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (178 votes), past polls