in reply to What does your old Perl code look like?
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. :)
|
|---|