Windows requires double quotes rather than single.
The activestate installation includes extensive documentation. Double click on the file 'C:\Perl\html\index.html'. This will include links to the documents that you hve already been refered to.
| [reply] |
$ cat > foo.tmp
gary is the best
frank is the worst
$ perl -i.bak -p -e 's/gary/harry/g;' foo.tmp
$ cat foo.tmp
harry is the best
frank is the worst
Bear in mind that by default regular expressions are Case-Sensitive.
Caveat: I'm using neither Activestate nor Windows.
To find out about the switches like -p and -e see perlrun. For regular expressions, try perlre. To get started in general try perlintro. Welcome to the wonderful world of Perl! | [reply] [d/l] |
perl -i.bak -p -e "s/gary/harry/g;" file.txt
Otherwise, you should really read the documentation, but these are quick answers to your question. The command line switches say:
-i
Inline editing, i.e. the file itself is modified (but, yes, there is some file renaming behind the scene);
-p
Assumes an input loop around the script to read all lines of the original file and print back the modified lines.
-e
the text coming between the quotes after this switch is to be taken as the Perl script to be executed (the more common usage, without the -e switch, is to put there name of the file containing the script.
s/source/target/ is the substitution operator. It replaces source with target. In this specific case, the substitution is applied to the string contained in the default $_ variable, which contains successively each line of the input file. The g modifier says that this substitution should be made as many times as possible (i.e. for all occurrences of source in the current string).
This was just a very quick answer to your questions (too short to be entirely accurate, but at least you should get the idea), there would much more to say, but go for the documentation you have been pointed to by other monks.
| [reply] [d/l] [select] |