Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Simple Perl Backup help

by davido (Archbishop)
on Aug 03, 2012 at 19:46 UTC ( #985336=note: print w/ replies, xml ) Need Help??


in reply to Simple Perl Backup help

A lot of your input code can be reduced to:

use IO::Prompt::Tiny qw/prompt/; my $answer = prompt("Yes or no? (y/n)", "n");

...by using IO::Prompt::Tiny. Then your user-input code could be reduced to the following:

if( prompt( "Backup $path? (y/n)", 'y' ) =~ m/^y/i ) { print "Backup beginning...\n"; perform_backups( @backup_dirs ); print "Backup complete.\n"; } else { print "No backups performed. Exiting.\n" } sub perform_backups { my @directories = @_; # Your backup code here. }

You could also warn instead of die if one or more backups failed, and then just keep on processing the rest (or prompt for what to do).<?p>

prompt() is convenient to use anywhere that user input is desired. If you need stronger input validation, IO::Prompt provides a richer set of tools, but adds some complexity.


Dave


Comment on Re: Simple Perl Backup help
Select or Download Code
Replies are listed 'Best First'.
Re^2: Simple Perl Backup help
by laxman526 (Initiate) on Aug 03, 2012 at 20:51 UTC

    Great info! Thank you so much. I'll add these tools to my Perl arsenal.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985336]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2015-07-07 20:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls