Just another Perl shrine | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Without seeing your "somefile.txt" I'm not sure what you are doing to get your $word. Certainly, the second chomp is superfluous as you can't remove the line terminator twice. My code below is the equivalent of yours except that I don't do the final chop as I can't tell whether it was necessary; it's easy enough to add back in. I perform the parsing of "somefile.txt" in a BEGIN {...} block before going on to append to the lines in the "address" file.
moritz points out that it can be a bad idea to edit a file in place. Perl does, however, have a handy -i flag for in-place editing which, if given an extension, will preserve your original file with that extension, the modified file taking the original name. Given a spurious "tcp" file and an "address" file
running this code (note the -i.bak flag
with the address file as the argument results in the original file preserved as spw638403.addr.bak and the modified file as spw638403.addr
I hope this is of use. Cheers, JohnGG Update: Clarified point that the scripts needs the name of the file to be modified as an argument. Update 2: Corrected senior moment with flag. It is, of course, the -i flag, not -p In reply to Re: Need a little help appending lines
by johngg
|
|