Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: For- loop increment not passing to inner block

by graff (Chancellor)
on Mar 30, 2008 at 21:51 UTC ( [id://677401]=note: print w/replies, xml ) Need Help??


in reply to Re^2: For- loop increment not passing to inner block
in thread For- loop increment not passing to inner block

I might not understand the overall task, but I would be inclined to invert the order of your two loops: the "while" loop over the file data should be the outer loop, and the "for" loop over columns in each line should be the inner loop.

If the file in question is not very big (e.g. less than, say, 50 MB on typical desktop machines of the last few years), and you have some reason to prefer your current ordering of the loops, it would be better to read the whole file content into a memory-resident array first, then use a nested "for" loop over that array, rather than repeating your "while" loop over the file contents.

The point is that file i/o is quite slow relative to memory-internal operations, so reading data from a file just once (rather than five times) just makes more sense.

  • Comment on Re^3: For- loop increment not passing to inner block

Log In?
Username:
Password:

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

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

    No recent polls found