Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How to process multiple input files?

by graff (Chancellor)
on May 22, 2011 at 20:51 UTC ( [id://906201]=note: print w/replies, xml ) Need Help??


in reply to How to process multiple input files?

I have tried to put the script within a foreach loop, but it did not work.

So, I'm guessing that you didn't try it this way:

#!/usr/bin/perl use strict; use warnings; for my $f ( @ARGV ) { local $/; open( I, '<', $f ); open( O, '>', "$f.bak" ); my $count = 0; my $line = <I>; $line =~ s{ (<\/div>) } { if (++$count == 2){ "\t<?php include(\$_SERVER['DOCUMENT_ROOT'].\"\/incl +udes\/footer.php\"); ?>\n\n".$1; } else { $1; } }gex; print O $line; }
That works for me. (BTW, I'm compulsive about making the indentation look right -- seems silly, but it's really helpful to keep code less illegible.)

If you have so many files that you can't fit them all as args on a command line, there's the unix "xargs" tool:

ls | xargs your_prog ## or use "find ... | xargs your_prog"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-03-28 16:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found