Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Far across cyberspace

by newrisedesigns (Curate)
on Jun 30, 2002 at 05:44 UTC ( [id://178323]=note: print w/replies, xml ) Need Help??


in reply to Editing a text file without reading it into an array

You could (but of course, TMTOWTDI):

open ($in, $infile) or die("Cannot open $infile"); open ($out, '>', $outfile) or die("Cannot open $outfile"); flock($out, 2); #lock output file while(<$in>){ ### edit each line here using $_ print $out $_; ## print each line to output } close($out); close($in);

As for monks to study, I suggest for starters looking at the posts of merlyn, tilly, jcwren, erudil, and crazyinsomniac (in no particular order).

Every monk here has something from which you can learn, and I'm sure you will have many ideas to contribute.

Update: followed Aristotle's suggestion and replaced foreach with while.
I should have known this, because "while(<$fh>)" was an answer to a question I previously asked. Sorry for the confusion, I'm just foreach happy. :)

John J Reiser
newrisedesigns.com

Replies are listed 'Best First'.
Re: Re: Editing a text file without reading it into an array
by cjf (Parson) on Jun 30, 2002 at 05:59 UTC
    As for monks to study...

    I recommend taking a stroll over to the Tutorials section. Most would probably find it serves as better introductory material than camel code ;-). Also, if you're looking for a good Perl book Learning Perl is an excellent choice.

      thanks :)
Re^2: Far across cyberspace
by Aristotle (Chancellor) on Jun 30, 2002 at 10:59 UTC
    Careful. foreach expands the bracketed list first so you still slurp the file. You only sidestep the declaration of a temporary array variable. Your code will however work exactly as intended - without the need for any other modifications - if you simply substitute foreach for while.

    Makeshifts last the longest.

Log In?
Username:
Password:

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

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

    No recent polls found