Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm struggling with the code for this. I've tried varoius things. The closest I've got isprompt user to enter a directory name Check if directory name exists If it does prompt user again and ask if the contents of the dir can be + overwritten. If it can continue with rest of program otherwise loop round again asking the same questions and doing the sam +e checks again . This bit may need to be run several times depending +on whether the user enters an existing dir or not.
It doesn't work. I'm fairly new to Perl and I suspect the code above reflects that ! This is on Unix (Solaris) . Any help is welcomeuse warnings; use strict; use Term::Prompt; use File::Find; no warnings 'File::Find'; sub Wanted; my ($dirname,$ans); $basedir="/dmp/backup"; $dirname = prompt('e', 'Enter a dir name', 'e.g. regression-EO +DDAY1', '','[A-Za-z0-9_-]+' ); # Check whether the dir already exists if find(\&Wanted, $basedir) { $ans = prompt('y', 'That dir already exists, do you wi +sh to overwrite the existing contents ?','[y/n]','n'); if ($ans = 1) { $dirname = prompt('e', 'Enter a dir name', 'e. +g. regression-EODDAY1', '','[A-Za-z0-9_-]+' ); } if find(\&Wanted, $basedir) { $ans = prompt('y', 'That dir already exists, d +o you wish to overwrite the existing contents ?','[y/n]','n'); if ($ans = 1) { $dirname = prompt('e', 'Enter a dir na +me', 'e.g. regression-EODDAY1', '','[A-Za-z0-9_-]+' ); } } } sub Wanted { my $dir = $File::Find::name; print if /$dirname/ ; return; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: A looping question
by graff (Chancellor) on Sep 10, 2010 at 13:32 UTC | |
Re: A looping question
by FunkyMonk (Chancellor) on Sep 10, 2010 at 09:52 UTC | |
by graff (Chancellor) on Sep 10, 2010 at 13:50 UTC | |
by Anonymous Monk on Sep 10, 2010 at 12:54 UTC | |
Re: A looping question
by JavaFan (Canon) on Sep 10, 2010 at 09:18 UTC | |
Re: A looping question
by Anonymous Monk on Sep 10, 2010 at 08:49 UTC | |
by Erez (Priest) on Sep 10, 2010 at 09:11 UTC | |
by Anonymous Monk on Sep 10, 2010 at 09:37 UTC | |
by Erez (Priest) on Sep 10, 2010 at 20:06 UTC |