Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Write a Perl program with a specific heuristic to take care of it. Something like:
    • Read in all the lines of the file
    • Walk thru the lines finding the one with bind parm 1. That's line $x.
    • Make sure that $line[$x+1] is bind parm 2, or else die because your heuristic isn't right.
    • @line[$x,$x+1] = @line[$x+1,$x];
    • $line[$x] =~ s/2/1/;
    • $line[$x+1] =~ s/1/2/;
    Or thereabouts. Seems to me that you don't need to switch the parms, but rather switch their bind numbers.

    It's a quick throwaway tool, but that's OK that you're going to throw it away. Better yet, keep it in some CVS project (we call ours "lab") that acts as a junk drawer, so you have it later on if you need to do something similar in the future.

    --

    --
    xoa

    • For a quick throaway tools, one can't beat perl one-liners. Here's one using the regex approach:

      perl -0777 pi.bak -e 's/\(1, ([^\)]+)\)(.*?)\(2, ([^\)]+)\)/(1, $3)$2(2, $1)/gs' file.pl

      Disclaimer: Not tested extensively.

      /prakash