Clear questions and runnable code
get the best and fastest answer
Re: Simple Perl Backup helpby moritz (Cardinal)
|on Aug 03, 2012 at 19:26 UTC||Need Help??|
If your perl is of version 5.10 or later, you can add
at the start of your script, and substitute all your print "something\n"; lines with say "something". Looks like a small code, but it does make it more fun to read and write.
As for your original question, you can write something like
This uses regexes to test for several values at once, laading to fewer branches with duplicate code. You could also write
if you don't want to use regexes.
Finally you should check the return value of system. Just because the backup file exists doesn't mean the backup was successfull. There could be a full file system, file system corruption, permission errors or other problems -- in which case tar will return a non-zero return code, which you should catch. See system for the full documentation on how to do that.