Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Append to beginning of line (multi line file)

by krujos (Curate)
on Jan 23, 2003 at 20:21 UTC ( #229415=note: print w/ replies, xml ) Need Help??


in reply to Append to beginning of line (multi line file)

You could just open and write the last one at the end. This should also fix your numbering problem.

open(INPUTFILE, "$file"); open(OUTPUTFILE, ">$outputfile"); my $counter = 1; while (<INPUTFILE>) { print OUTPUTFILE "$counter. $_"; $counter++; } close(INPUTFILE); close(OUTPUTFILE);
If you want to copy over the old file, just do it at the end.

UPDATE: You should probably check to make sure the files actually open (using die) like you did in your original code.

UPDATE2: Only now does command line register in krujos' head. Doh!


Comment on Re: Append to beginning of line (multi line file)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-07-30 03:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls