Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: File handle question

by hatter (Pilgrim)
on Aug 12, 2005 at 12:15 UTC ( [id://483256]=note: print w/replies, xml ) Need Help??


in reply to File handle question

If you start off with
open (FCMP, "anchor.txt") or die ("anchor.txt is not opened\n"); my @file = <FCMP>;
you can then replace while(<FCMP>) with foreach (@file) and the replace the second loop in its entirety, with print join("\n",@file)

If you want bonus cleverness, you could even replace the first loop with a single map() command, but that's probably leaping a step or two up on the learning curve.

Either way, as others have said, using <> steps through each line of input, you can either seek or re-open the file to go back to the beginning, or simply read the file into an array first, which avoids having to read the file from disk an extra time (a more expensive operation)



the hatter

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-03-28 20:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found