I seek your help for on this little problem.
Executing the code below gives error "Use of unitialized value in subtraction at line 70". This is line 70:
if (time - $ftp->mdtm($_) > $maxage) { push(@return, $_); }
I have looked at the code and it didn't helped. So I tried to find what is unitilized but I haven't found anything:
Please, I feel completely blind and I don't want to remove use strict just because it is complaining.
Execution:
[pcsson@psr-iccdrift op5]$ ./ftp.pl -u loollippop -P pitamikabyta -m m +y_machine -d hippohumpa -a 10 -s hej Use of uninitialized value in subtraction (-) at ./ftp.pl line 70. 2 stuck files stuck on hej
Code:
#!/usr/bin/perl use warnings; use strict; use Net::FTP; use Getopt::Long; # Todo: Installera #use Getopt::Long::Configure ("bundling"); use Pod::Usage; # Parameters that user can supply my ($user, $pwd, $machine, $dir, $port, $filter, $maxage, $name); my ($ftp, @stuck); # Exit codes. Fetched from # http://www.op5.com/support/documentation/plugin-development my ($OK, $WARNING, $CRITICAL) = (0, 1, 2); # Resonable defaults where we can. ($port, $dir, $filter, $maxage) = (21, ".", ".*", 3600); sub err { print @_, "\n"; exit $CRITICAL } sub parse_options { my %options = (); $options{'h|help'} = sub { pod2usage(-verbose => 2, -output => \*S +TDERR); exit -1; }; $options{'u|user=s'} = \$user; $options{'P|password=s'} = \$pwd; $options{'m|machine=s'} = \$machine; $options{'p|port'} = \$port; $options{'d|dir=s'} = \$dir; $options{'f|filter=s'} = \$filter; $options{'a|age=i'} = \$maxage; $options{'s|servicename=s'} = \$name; GetOptions %options; # Do validation. Port, dir, pwd, machine, user are all mandatory $user or err "Must specify username\n"; $pwd or err "Must specify password\n"; $machine or err "Must specify machine\n"; if (!$name) { $name="ftp://$user:$pwd@$machine:$port/$dir/$filter" +; } } sub retrieve_listing { $ftp = Net::FTP->new($machine, Port=>$port) or err "Cannot connect to $machine:$port\n"; $ftp->login($user,$pwd) or err "Cannot authenticate $user\n"; my @return = $ftp->ls($dir); @return; } sub filter_name { # Filters directory listing by name specified by the filter flag o +ption grep /$filter/, @_; } sub filter_time { # Filters out files based on the my @return = (); for (@_) { if (time - $ftp->mdtm($_) > $maxage) { push(@return, $_); } } @return; } parse_options; @stuck = filter_time filter_name retrieve_listing; $ftp->quit; if (@stuck) { err scalar(@stuck) . " stuck files stuck on $name"; } else { exit 0; } __END__
In reply to Use of unitialized, why? by aquaplanet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |