Perl just saved me a heck of a lot of time, although I had to do a little old-school work too. I ended up creating a little edit decision list program.

The other night I needed to edit a really long article for The Perl Review. The computer screen just wasn't doing it, so I printed it, cut it up, rearranged the bits, and pasted them up. Now the really long article was cut down to something that would actually fit in the magazine.

From there, I had to transform the original text into the hard-copy pasted-up version I had. I could cut-and-paste all the ranges, of which there are many, but that would take a lot of mouse work and window switching. All the lines on the hard copy had line numbers, so I knew which lines numbers I wanted where.

Enter Perl. I typed in all the line ranges, in the order I wanted them. I then read those, parsed them, and printed out the corresponding line of the original file.

That gets me pretty close to a point where I can go back to the normal editing process.

#!/usr/bin/perl my @lines = do { open F, "article.pod"; ( undef, <F> ); }; foreach ( <DATA> ) { my( $start, $stop ) = m/(\d+).*?(\d+)/g; print "\n"; foreach my $line ( $start .. $stop ) { print $lines[$line]; } print "\n"; } __DATA__ 10-24 60-65 57-60 65-69 113-115 42-45 51-53 70 89 81 76-77 85 93-94 99-98 103-105 198-224 248-253 244-247 225-243 255-280 46-49 116-122 55-56 281-336 25-37 399-416 5-8 521-524

The only tricky part of the code is the array indexing. The line numbers start at 1, but Perl starts at 0. When I read the original file, I put an undef in the zero-th position of @lines. Then, everything lines up and I don't need any ugly offsets in the code. I probably could have fooled with the deprecated $[, but the undef works just fine.

--
brian d foy <bdfoy@cpan.org>

In reply to A little edit decision list in Perl by brian_d_foy

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.