Beefy Boxes and Bandwidth Generously Provided by pair Networks
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).

perl -"MFile::Dosglob" -e "sub NX{return shift @ARGV;};$P=quotemeta NX;$S=NX;$gb=NX; $opt_t=($t=NX)?$t:undef; push @ARGV,glob(qq{*.$gb}); @O=@Y=@ARGV; for(@O){ $T{$_}=(stat $_)[9]; print qq{\n},$_,q' ',($lt=localtime($T{$_})),qq{\n} ;} if (! $opt_d){for (@O){splice @O,$n++,1,q{\"}. $_ .q{\"};} open(TF,qq{>TMP.~});print TF join qq{\n},@O,$S,$P;close (TF); ($ev=scalar eval qx{TYPE e:\\scr\\p-in-p.p}) or warn $@; if ($opt_t){ for(@Y){ print STDERR qq{\n$_ ! };$r+=utime(time,$T{$_},$_); }; print qq{\n\n Filetimes restored for $r files out of $ev files.\n\n};}}" "i" "I" "txt" -t

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <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>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-19 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found