Hello again, Datz_cozee75,
For user input with timeout, you can use the Prompt::Timeout module:
use Prompt::Timeout; use constant TIMEOUT => 5; ... if (defined($size_remote)) { my $default = ($size_remote == $size_local) ? 'N' : 'Y'; my $answer = prompt('Overwrite?', $default, TIMEOUT); upload($_) if $answer =~ /^Y/i; # overwrite } else { upload($_); }
Notes:
If $size_remote is undef, testing it with eq or == will produce a warning — so don’t do that.
$size_remove and $size_local are both integers, so prefer == to eq for the equality comparison.
Two additional observations:
The loop condition:
while (defined ($_ = readdir($eh)))
can be written more concisely as:
while (readdir($eh))
It’s inefficient to use captures in a regex if those captures aren’t needed. Use grouping (non-capturing) parentheses:
my $pattern = join '|', map "(?:$_)", @filetypes;
or, in this case, omit the parentheses altogether:
my $pattern = join '|', @filetypes; ... while (readdir($eh)) { next if /~$/ || -d || !/$pattern/i; ...
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^2: a full-featured control for uploading files
by Athanasius
in thread a full-featured control for uploading files and a couple other tidbits
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |