Dear Gods over Earth, Water, Fire, Water and PERL!

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.