FILE_LIST=`ls *.wrk` for FILE in $FILE_LIST do logit "COPYING $FILE TO $TGT_DIR" cp $FILE $TGT_DIR logit "PROCESSING $FILE FOR GROUP1" perl /some/other/script.pl <$FILE >>TMPOUT 2>>err.rpt rm -f $FILE done
So something happens to the files in the CWD, the output is concatenated to TMPOUT, and later more processing is done on the files copied to $TGT_DIR, which are just the original .wrk files. Like so:
cd $TGT_DIR FILE_LIST=`perl /rename/by/id.pl $FILE_NAME` for FILE in $FILE_LIST do if perl /some/compliance/checks.pl $FILE 2>/dev/null >$FILE.ERR then cp -f $FILE archive cp -f $FILE out else logit "$FILE WAS MALFORMED:\n `cat $FILE.ERR`" mail -s "FILE $FILE INCOMPLETE, NOT SENT" $NOTIFY <<EOF FILE $FILE NOT SENT BECAUSE: `cat $FILE.ERR` EOF fi
I'm wondering if my time would be better spent creating a Perl script to replace the shell script, and import the Perl scripts as functions, or tracing everything that each script is doing, and build a new script that reduces everything to the essentials. For example, /some/other/script.pl and /some/compliance/checks.pl both do compliance checks for different groups in my company, and copy files if they pass to the appropriate directories. These could be combined into one script that compliance checks everything in one pass of the file, checks the IDs on the fly and does what /rename/by/id.pl would normally do.
I could spend a week or so trimming the 500 line monstrosity down to around 100 lines of just-the-essentials, or I could spend two days refactoring and documenting, and leave it looking like a giant, bloated mess. Each Perl script is also its own breed of hell, e.g.:
$FILENAME=shift; ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$bl +ksize,$blocks)= stat($FILENAME); ($fsec,$fmin,$fhour,$fmday,$fmon,$fyear,$fwday,$fyday,$fisdst) = local +time ($mtime); $fyear=$fyear+1900; $fmon++; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(t +ime); $year=$year+1900; $mon++; open (INFILE,$FILENAME); while (<INFILE>) { chomp; if (m/(^[0-9]{2})/) { $RecordCount++; $STATS{"$1"}++; @Record=split(",",$_); if ($Record[0] eq '01') { $CREATE_DATE="20$Record[3]"; $DATESTRING=sprintf("%04d%02d%02d",$year,$mon,$mday); if (($DATESTRING-$CREATE_DATE)>2){ $WARNINGS{"01 Date looks old"}++; }; }; # etc.
Nice date delta function. Need I go on? I don't want code like that being my code and to be charged with supporting it. My question to the community is: What would you do? Have you ever been in a similar situation? How did it turn out?
In reply to Refactor and simplify by delirium
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |