The first thing I ever posted here was the first real perl program I had ever "cronned" on my system. It was a useful little script to backup directories and allowed for exclusion of file/sub directories.. well I tweaked it a bit recently to be much nicer looking and alot more functional as far as reporting info to the user of the program.. so here's the new backup.pl that's running on my system:
#!/usr/bin/perl -w # # Script used to back up files to another # partition. # # Code by Brad Lhotsky <brad@divisionbyzero.net> # $|++; use strict; ########################### # Configs: # my $MOUNT = "yes"; my $PARTITION = "/dev/hdd1"; my $MOUNTPOINT = "/mnt/tmp"; my $BACKUPDIR = $MOUNTPOINT; my $CONFIG = "/root/backup/backup.conf"; my $ERRORFILE = "/root/backup/backup.err"; die "config file $CONFIG couldn't be found: $!\n" unless -e $CONFIG; my %TARS=(); unlink($ERRORFILE) if -e $ERRORFILE; if($MOUNT) { system("mount $PARTITION $MOUNTPOINT"); } open(CFG, "<$CONFIG") or die "couldn't open $CONFIG: $!\n"; while(local $_ = <CFG>) { chomp; s/^\s+//; s/\s+$//; next if /^#/; next if !$_; (local $_, my @JUNK) = split /#/; s/^\s+//; s/\s+$//; my ($tarfile,$directory,@EXCLUDES) = split; push @EXCLUDES,'..'; push @EXCLUDES,'.'; my $ok = &backup($tarfile,$directory,\@EXCLUDES); if($ok) { print "Tarred $tarfile successfully! ($directory)\n"; $TARS{$tarfile}=1; } else { print "Tar of $directory to $tarfile failed!\n"; } } foreach my $tarfile (keys %TARS) { &compress($tarfile); } if($MOUNT) { system("umount $PARTITION"); } sub backup { my ($tarfile,$dir,$exc) = @_; return 0 unless $tarfile && $dir && $exc; if($dir !~ /\/$/) { $dir .= '/'; } if($tarfile !~ /^\//) { $tarfile = $BACKUPDIR . "/$tarfile"; } my $check = "$dir/.tar"; return 0 unless -e $check; if(-e $tarfile) { return 0 unless -d $dir; opendir(LS, $dir) or die "couldn't open $dir for listi +ng: $!\n"; while(local $_ = readdir(LS)) { #chomp; my $skip=0; foreach my $file (@$exc) { $skip=1, last if ($_ eq $file); } next if $skip; my $file = $dir . $_; my $append = "tar -rf $tarfile $file 2>> $ERRO +RFILE"; system($append); print "\t$file\n"; } print "$tarfile appended to!\n"; } else { my $create = "tar -cf $tarfile $check 2>> $ERRORFILE"; print "$tarfile created!\n"; system($create); &backup($tarfile,$dir,$exc); } } sub compress { my $tarfile = shift; if($tarfile !~ /^\//) { $tarfile = $BACKUPDIR . "/$tarfile"; } my $gzipit = 'gzip -f ' . $tarfile . '.gz ' . $tarfile . " 2>> + $ERRORFILE"; print "GZipping $tarfile .... "; system($gzipit); print "done!\n"; }

I know its nothing great, but compared to the old one, its definately a step up.

feel free to go "WTF ARE YOU DOING THAT FOR????? DO THIS:", I always welcome criticism, its the only way to get better.
thanks to everyone who's helped me in the past.

UPDATED
I took most fo your suggestions, haven't had time to download/install any modules to make this look nicer..
thanks for your input ;)
-brad..

In reply to Evolution of a Perl Programmer (new backup script) by reyjrar

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.