Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: copying a file with .bak extension

by Lotus1 (Curate)
on Nov 07, 2012 at 19:06 UTC ( #1002718=note: print w/replies, xml ) Need Help??

in reply to [SOLVED] copying a file with .bak extension

From How can I use Perl's i option from within a program? the -i option changes $^I which in turn changes how <> works. That means the magic only works inside a while loop that uses <>. Your code with -i added on for me made a .bak copy but cleared the original and printed to the command line. The following code does what you requested.

#!/perl -i.bak while(<>) { print; if(eof) { print "\n"; print "##Copyright (C) 2012 by firstName lastName\n" ; } }

Replies are listed 'Best First'.
Re^2: copying a file with .bak extension
by Anonymous Monk on Nov 07, 2012 at 19:20 UTC

    Script works great thanks a lot! Is it possible to have the backup get modified instead of the original? Only the original gets the modification. Thanks again.

      You could use kennethk's updated solution but open the newly created backup in append mode instead of the original.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002718]
[Veltro]: erix Corion Ofc it is possible. A while back people thought it was not possible to create an app that can detect what you are listing to.
erix puts the needle in the groove
[marto]: depending on what you qualify to be "a while back" that was true :P
[erix]: probably everything was
[marto]: exactly

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2018-05-24 11:51 GMT
Find Nodes?
    Voting Booth?