[LA.pm] Spam:***, Re: little help??

Mike Dillon md5 at embody.org
Wed Sep 28 20:00:17 PDT 2005


begin FamiLink Admin quotation:
> Also, the sub scanlog does write the information to the files but it does 
> not return anything back to the main program and I also get the error:
> 
> Use of uninitialized value in split at ./test.pl line 9.
<snip>
> ------------------------------------------------------------------------------
> #!/usr/bin/perl -w
> require Mail::Send;
> $|=1;           # no buffering
> use constant IP_LIST_FILE => "/etc/squid/iplist.txt";
> use constant SUSPEND_FILE => "/etc/squid/SuspendIpList.txt";
> use constant LOG_FILE => "/opt/n2h2/logs/filter_log";
> my $sysop = "webmaster\@familink.com";
> my $flag = "PO";
> my $hour = (split, localtime)[2];

This is your old friend $_ biting you in the ass again.

The comma after split is the problem. Using split with no arguments is
basically the same as doing "split ' ', $_". Since $_ is undefined,
you're getting a warning.

Really, though, you shouldn't be trying to split the string returned
from localtime. You should use it in list context like so:

    my $hour = (localtime)[2];

In list context, localtime returns a numeric list of the parts of time.
This avoids putting localtime into scalar context where you are forced
to have to parse it with split.

Many built-in Perl functions have this dual mode of operation in scalar
versus list mode. A good explanation can be found at
<http://perl.plover.com/context.html>.

-md


More information about the Losangeles-pm mailing list