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.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |