Balinor has asked for the wisdom of the Perl Monks concerning the following question:

#!/usr/bin/perl -w use strict; my @res; my ($users,$time,$up,$uptime,$res); @res = `/usr/bin/ftpcount --path=/var/run`; $time = time(); foreach $res (@res) { if ($res =~ /(\d+)\susers/) { $users = $1 } else { next } } $uptime = `uptime`; $uptime =~ /up (.*?),/; $up = $1; print "Content-type: text/html\r\n\r\n"; print "$users\n"; print "$users\n"; print "$up\n"; print "ftp.xxxxxx.com\n";

generates this:

Content-type: text/html Use of uninitialized value in concatenation (.) at ./ftpstat.pl line 2 +1. Use of uninitialized value in concatenation (.) at ./ftpstat.pl line 2 +2. 6:34 ftp.xxxxxx.com

what am i doing wrong?

2001-03-03 Edit by Corion : Changed title to something more descriptive, updated formatting.

Replies are listed 'Best First'.
Re: help please!
by grinder (Bishop) on Feb 22, 2001 at 13:32 UTC

    This if statement

    if ($res =~ /(\d+)\susers/) { $users = $1 } else { next }
    is never true so $users is never being set. As you did explicitly initialise it to 0, you are asking print to represent the undef value. So just say $users = 0; before the foreach scan.

    Oh, and that next is redundant (or else you may want to consider using last instead.