(view source code of far.pl as plain text)
#! perl
# Check command line arguments
if ( !@ARGV[2] ) {
print "\nFaR -- Find and Replace, Version 1.01\n";
print "Search a string for a substring and replace it with another substring\n\n";
print "Usage: FAR.PL \"string0\" \"string1\" \"string2\" [ -I ]\n\n";
print "Where: \"string0\" is the string to be searched\n";
print " \"string1\" is the substring to search for\n";
print " \"string2\" is the substring that should replace string1\n";
print " -I makes the search case insensitive\n\n";
print "All strings must be enclosed in double quotes and \"escaped\".\n\n";
print "Written by Rob van der Woude\n";
print "http://www.robvanderwoude.com\n";
exit(1);
}
# Parse command line arguments
$string0 = @ARGV[0];
$string1 = @ARGV[1];
$string2 = @ARGV[2];
$caseon = "";
$caseoff = "";
if ( @ARGV[3] ) {
if ( uc( @ARGV[3] ) eq "-I" ) {
$caseon = "(?i)";
$caseoff = "(?-i)";
}
}
# Search and replace using a regular expression
$string0 =~ s/$caseon$string1$caseoff/$string2/g;
# Display the end result
print "$string0\n";
page last modified: 2024-04-16; loaded in 0.0049 seconds