in reply to Simple Perl Backup help
If your perl is of version 5.10 or later, you can add
use 5.010;
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
if ($input =~ /^(y|yes)$/) { say "Backup is beginning..."; last; } elsif ($input =~ /^(n|no)$/) { die "Program is shutting down.\n"; } else { say "This is not a valid answer."; say "Please enter 'yes' or 'no'"; }
This uses regexes to test for several values at once, laading to fewer branches with duplicate code. You could also write
if ($input eq 'y' || $input eq 'yes') { say "Backup is beginning..."; last; }
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple Perl Backup help
by laxman526 (Initiate) on Aug 03, 2012 at 19:32 UTC |