Re: "Convert" perl command line to simple script
- From: "Jürgen Exner" <jurgenex@xxxxxxxxxxx>
- Date: Thu, 28 Jun 2007 16:28:22 GMT
bluez34me@xxxxxxxxx wrote:
Here's an example of a script that I'm running to clean up html pages
that I'm generating automatically:
perl -pi -e 's/..\index/index/g' *.html
Is there some "standard" and simple way to get this into script form,
or do I need to write a complete script that handles looping through
the files, does the regex handling and all that?
Well, let's check what those command line parameters do (from perldoc
perlrun):
-e *commandline*
may be used to enter one line of program. If -e is given, Perl will
not look for a filename in the argument list. Multiple -e commands
may be given to build up a multi-line script. Make sure to use
semicolons where you would in a normal program.
Ok, that's trivial.
-i[*extension*]
specifies that files processed by the "<>" construct are to be
edited in-place. It does this by renaming the input file, opening
the output file by the original name, and selecting that output
file as the default for print() statements. [...]
Seems this is one you will have to code yourself.
-p causes Perl to assume the following loop around your program, which
makes it iterate over filename arguments somewhat like sed:
LINE:
while (<>) {
... # your program goes here
} continue {
print or die "-p destination: $!\n";
}
This one you will have to implement yourself, too (although that should be
rather trivial given this template).
And of course you will need to loop through all the file names resulting
from the shell glob expansion.
jue
.
- Follow-Ups:
- Re: "Convert" perl command line to simple script
- From: Paul Lalli
- Re: "Convert" perl command line to simple script
- References:
- "Convert" perl command line to simple script
- From: bluez34me
- "Convert" perl command line to simple script
- Prev by Date: Re: Oh great gurus of the list, I need help with a regular expression please
- Next by Date: Re: "Out of memory!" ???
- Previous by thread: "Convert" perl command line to simple script
- Next by thread: Re: "Convert" perl command line to simple script
- Index(es):
Relevant Pages
|
|