My old HDD is never too far away:

#! /usr/bin/perl use strict; use warnings; use Storable; use Scalar::Util; use File::Basename; use POSIX; my $busy = 'busy'; my $is_busy; if (-e $busy) {$is_busy = ${retrieve($busy)}} else {$is_busy = 0}; if ($is_busy) {exit}; $is_busy = 1; store(\$is_busy, $busy); my $magic_string = ' -depth 8 -density 150 -compress Zip '; my $mydata = 'mydata'; my $folder = 'Hot'; my $folder_done = 'Done'; my @fl1; my @a1; my %fl2; sub find_index { my $tmp = -1; my $str1 = shift; my $str2 = shift; my $size1 = length $str1; my $size2 = length $str2; if ($size1 != $size2) {return -1}; for (my $i = 0; $i < $size1; $i++) { my $c1 = substr $str1, $i, 1; my $c2 = substr $str2, $i, 1; if ($c1 ne $c2) { if ($tmp != -1) {return -1} else {$tmp = $i} } }; return $tmp }; sub good_pair { my $str1 = shift; my $str2 = shift; my $n = find_index($str1, $str2); if ($n == -1) {return 0}; my @tmp = sort (substr($str1, $n, 1), substr($str2, $n, 1)); if ((ord($tmp[0]) < ord('A')) or (ord($tmp[1]) > ord('Z'))) {retur +n 0}; unless (ord($tmp[0]) % 2) {return 0}; if (ord($tmp[1]) - ord($tmp[0]) - 1) {return 0}; return 1 }; # ******************************************************** opendir DIR, $folder; @fl1 = readdir DIR; closedir DIR; if (-e $mydata) {%fl2 = %{retrieve($mydata)}}; # ... # hundred+ lines of more horrors (I'll spare you ...:) ), then: for (my $i = 0; $i < @pdf; $i++) { system "lpr -o orientation-requested=3 -o media=Custom.".$w[$i]."x +".$h[$i]."mm ".'"'.$folder."/$pdf[$i]".'"'; rename $folder."/$pdf[$i]", $folder_done."/$pdf[$i]"; }; store(\%fl2, $mydata); $is_busy = 0; store(\$is_busy, $busy);

1st check if still busy i.e previous cron job was not finished. Next couple of funny subs are to determine "good pair" of ~ISO-A2 tiff files, face and back, names differ in single char, A & B or C & D... but not e.g. B & C. Skipped part is head to head imposition, IM system calls, +some other fuss, dense and unreadable.

That's how it started, with Linux, and, quite arbitrarily, Perl as scripting language, in 2007, because of "free" lpr to print jobs from hotfolder to wide-roll printer. Not "old code", for that I'd dig for Pascal from 1990 or so. :)


In reply to Re: What does your old Perl code look like? by vr
in thread What does your old Perl code look like? by haukex

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.