perl -e inside another perl -e ? 
Author Message
 perl -e inside another perl -e ?

Hi folks, here's a tricky one:

The following perl one-liner adds a line at the top of the file "myfile".
perl -p -i.bak -e '{ ($.==1) && print "line 1\n"; }' myfile

How do I modify the above script to work on multiple files ? I was thinking
of putting a "perl -e" outside the above code, but I'm not sure how to do
it. I can always write a for/foreach loop; but i want to keep it a one-liner.

--Ravi



Tue, 21 Sep 2004 12:16:21 GMT  
 perl -e inside another perl -e ?

Quote:

> Hi folks, here's a tricky one:

> The following perl one-liner adds a line at the top of the file "myfile".
> perl -p -i.bak -e '{ ($.==1) && print "line 1\n"; }' myfile

> How do I modify the above script to work on multiple files ?

perl -p -i.bak -e '{ ($.==1) && print "line 1\n"; $. = 0 if eof }'

This newsgroup does not exist, please do not start threads here.



Tue, 21 Sep 2004 19:03:25 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Executing Perl scripts inside a Perl script

2. Running perl scripts inside perl scripts (TIA)

3. perl script inside perl script

4. lvalue sub doesn't work inside perl debugger

5. running less from inside perl

6. Perl to convert DOS commands inside Unix !!!!!!

7. shell calls from inside perl

8. Using perl inside of Tcl

9. Need help learning how to use chown correclty inside of a perl script

10. Perl inside Apache clues

11. perl does not treat # inside `` properly

12. Reading binary file created a C++ program inside a Perl prog

 

 
Powered by phpBB® Forum Software