Slash Boxes
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.
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



    • 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'

      Disclaimer: Not tested extensively.


  • There is some improvement to be made.

    /2CR         # (CR is return) search for the 2 (or some other way to get there)
    r1kr2        # change 2->1, up, change 1->2
    ddp          # delete 1'st line, append 1'st line after 2'nd

    The "r" is useful to change one character ("R" will overwrite a bunch of chars, it's like insert mode but overwrites).

    The "ddp" switches the current line with the next. It is a variant on the very useful (especiall

    • I found one aspect of vi that prepared me well for Larry's view of perl (that writing pidgin perl is a great way to start and should be tolerated, nay encouraged).

      I found that my initial use of vi was adequate, but that every 6 months or a year I would read through the vi manual and pick a few more useful idioms and add them to the set that I knew well enough to use without thinking. After a few years of this, my vi repertoire was large enough that most of the new idioms I tried to learn were not useful o

  • With vim, where the C-A and C-X commands are available to increment and decrement numbers, I'll probably be doing (without thinking much), from the 1st line :
    • Hmm. I didn't know about these. Learnt something new.

      Also, to make it even easier, a temporary binding can be created using map.

      :map <C-Q>  <C-A>ddpk<C-X>

      Of course, a better (preferably unused) key may be used in place of

      I just chose that as it is rarely used, I think.


    1. Move the cursor to the space after the comma in the param list.
    2. Press "r[Enter]"; replaces the space with a newline.
    3. Do the same on the other line.
    4. Now, move to the line that has the second arg from the first line.
    5. Press "ddp"; moves it after the former second line.
    6. Go down one line to the second argument from the second line.
    7. Press "ddkkP"; moves it after the first line.
    8. Go up to the first line.
    9. Press "J" to join the two lines into one putting a space between the two pieces.
    10. Go down to the next line, and