I occasionally am required to do some exceptionally boring task at $work. Such tasks drive me nuts (click, drag, good monkey!). The upside is, most of them can be automated to some extent, which tasks provide an opportunity to improve my Perl-fu and save time in the process - I find that performing the whole task manually is usually slower than writing a Perl script to do the job.

The most recent annoyance involved a static-HTML web page that we had neither time nor budget to rewrite using a database. I needed certain page elements each given a unique ID tag (to facilitate a drop-down, flashy image gallery thing). And the elements needed to be sorted by title in alphabetical order. Worse yet was that I didn't have all the elements to be added up front; a designer was sending them to me rather serially. I wasn't about to renumber 100/2 (on average) IDs each time an element was added, so out came Perl:

#!perl -pi.bak BEGIN { $i = 0; $next_regex = qr/toggle[(]/i; } $i++ if /$next_regex/; $num = sprintf "%02d", $i; s/toggle[(]'\d+'[)]/toggle('$num')/; s/icon_details_\d+/icon_details_$num/; s/details_\d+/details_$num/; s/gallery_\d+/gallery_$num/;

How easy was that! Run each time the page got a new element, it saved me half an hour and took maybe 5 minutes to write. Thanks, Perl! :)

So, how has Perl saved you time at your job recently? Specific examples would be great; code would be even better.


undef $lunches{free}

In reply to How has Perl saved you time at your job this week|month|year|decade? by missingthepoint

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.