Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
First, the one-liner itself (shown with arbitrary example arguments and -t switch set), followed by the script file p-in-p.p (I follow a naming convention of making Perl application -- executable -- scripts with names *.p, library code in files named *.pl). Also, please save the file
p-in-p.p (or whatever you want to
name it) to a reasonable location on your
HD and then edit the one-liner below so the
system can find it there (fully qualified path
specification).
The script file:
#!perl
#p-in-p.p
open LOG, ">LOG.~" or die $!;
@ARGV = split /\n/,`TYPE .\\TMP.~`;
print LOG "Patterns: ",qq{\n} x 2, join qq{\n}, @ARGV[$#ARGV,$#ARGV-1]
+,qq{\n};
$P=pop @ARGV;
$S=pop @ARGV;
@ARGV = sort {uc($a) cmp uc($b)} @ARGV;
print LOG "\n" . @ARGV . " Files: ",qq{\n} x 2, join qq{\n},@ARGV, qq{
+\n};
@ARGV = &Dequote(@ARGV);
my $countfiles = $#ARGV + 1;
$^I=q{.PBU};
$S =~ s#\\@#@#g;
while (<>){
my $former = $_; chomp $former;
if (s/($P)/$S/g){
print LOG qq{\n},q{ Now in file: },
$ARGV , qq{:\n};
print LOG qq{Replacing: *${1}* in: } .'"' . $former . '"' .qq{
+\n}.
qq{with: } .'"'. $_ .'"'. qq{\n};
print;
}
print;
};
close (LOG);
system "notepad LOG.~";
sleep 3;
unlink qw{LOG.~ TMP.~};
return $countfiles;
sub Dequote {
for (@_) {
$_ = substr ($_,1,(length $_) - 2);
}
return @_;
}
In reply to In-Place editing system by Intrepid <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul> |
|