[LA.pm] little help??

Bob Mathews bobmath at sbcglobal.net
Wed Sep 28 19:59:47 PDT 2005


On Sep 28, 2005, at 4:35 PM, FamiLink Admin wrote:
> ...I am not sure what to do about:
>
>> Paranoia time: are you certain that $log doesn't contain anything 
>> dangerous that will make the shell misbehave? Probably not, but if 
>> you're putting this in a CGI script that takes $log as a parameter, 
>> it's something you need to think about.

You're using a constant for the filename now, so no worries. The 
original code looked like this:
    open my $slog, "-|", "tail -n 50000 $log"
Which is a big problem if someone manages to set $log to something like 
"foo;rm -rf *". Try it out, but make sure you're in a directory that 
doesn't contain anything important.

> Also, the sub scanlog does write the information to the files but it 
> does not return anything back to the main program

It does return stuff, but a lot of it is undefs. You have some scoping 
trouble going on, it looks like. The standard reference is Coping With 
Scoping (http://perl.plover.com/FAQs/Namespaces.html). Also consider 
the output from this:
    my $x = 42; print "x = $x\n";
    { my $x = 23; print "x = $x\n"; }
    print "x = $x\n";

> and I also get the error:
> Use of uninitialized value in split at ./test.pl line 9.

By my count, line 9 is:
    my $hour = (split, localtime)[2];
Split followed by a comma means split(), which splits $_, which must be 
undefined. Think you want to ditch the split in that statement.

> Also, is there a better way of counting the number of times each IP 
> address gets blocked with category PO?   Each time I get to the 
> blocklimit it writes to the file but I really just want the max number 
> of blocks over the limit. It will write the same IP each time it gets 
> over the blocklimit though.

Not sure I understand you fully, but you might want to total up the 
number of blocks for each ip thusly:
    $blocks{$ip}++;
And then print out the totals once you've processed the entire file.
    while (my ($ip, $count) = each %blocks) { ... }

> $|=1;           # no buffering

Don't think this is doing anything for you. It's only setting autoflush 
on STDOUT, and you're not printing very much there.

   -bob



More information about the Losangeles-pm mailing list