Your main problem is that you need to split the line you're passing to ban()

m|/sorry/| && ban(split ' ', $_);

With that input, your above three lines would start to make some sense.

Thing is that, in contrast to command line arguments, a string you pass as one parameter to a subroutine is not automatically split.  I.e., when you say on the command line

# ./script.pl foo bar baz

you get the three words "foo", "bar", "baz" as separate elements in the array @ARGV (which I suppose you were using in the working command line version in place of @_). This is because the shell splits the command line on whitespace, before the arguments are placed in @ARGV.

OTOH, when you pass "foo bar baz" as a single string to a subroutine, it is left as is, so the array @_ holds one element, which is the entire string.  In other words, after your grep for /proxy_/, you still have the entire string in @cutoff — and the rest of the code stops working...

That said, you could also leave your ban($_) call as is, and simply extract the relevant part of the string with a regex capture:

sub ban { my $line = shift; ... my ($proxy) = $line =~ m| - \S+/(proxy_\S+)|; my @cutoff = grep /$proxy/, @cfg; ...

In reply to Re^7: Real time log parser by Eliya
in thread Real time log parser by kazak

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.