in reply to Re: regex not working..
in thread regex not working..

Thanks.. now just having the problem that it wont accept any of these:
if (index($input, "/QUOTE") != -1) { my $str = $input; ($pass) = $str =~ m{/QUOTE\sPASS\s(.*?)$}; print $sock "/QUOTE PASS $pass\r\n"; print $sock "QUOTE PASS $pass\r\n"; print $sock "/QUOTE PASS$pass\r\n"; sleep 2; print $sock "QUOTE PASS $pass\r\n"; print "found quote $pass\r\n"; }
as you can see im trying everything heh.. this is for my channel bot, currently i dont have X so im using it to op me and other operators and also to auto ban on certain words

Replies are listed 'Best First'.
Re^3: regex not working..
by AnomalousMonk (Archbishop) on May 12, 2012 at 17:35 UTC
    ... it wont accept any of these ...

    Not sure what you mean by 'it' (since you do not supply a self-contained, runnable code example) or 'these' (since you don't supply the data in your strings), but your code (as well as all the possibilities suggested by davido) seems to work for me.

    >perl -wMstrict -le "my $str = 'NOTICE AUTH :*** Bla bla must type /QUOTE PASS 16934'; my $pass; ($pass) = $str =~ m{/QUOTE\sPASS\s(.*?)$}; print qq{'$pass'}; " '16934'
      if i included the code the post would be massive. what im doing is connecting to an irc server.
      irc response while trying to connect: NOTICE AUTH :*** Ident broken or disabled, to continue to connect you +must type PASS 16934
      -code to answer the question.
      my $pass; while (my $input = <$sock>) { if (index($input, "/QUOTE") != -1) { my $str = $input; ($pass) = $str =~ m{/QUOTE\sPASS\s(.*?)$}; print $sock "QUOTE PASS $pass\r\n"; } }
      nothing happens..

        Maybe you want to test your code outside of your irc bot, in a short program that you can also post, so we can also try it to see where it goes wrong?

        Also, have you considered Bot::BasicBot or the other Bot modules that CPAN provides instead of rolling your own?

        if i included the code the post would be massive.

        No one wants all the code, massive or otherwise. What Monks like to see is small, self-contained, runnable example code (along with input and desired output) demonstrating the problem. You actually provided such an example in your OP, and this is the code (and data) to which davido and I responded. Please see How do I post a question effectively?, How (Not) To Ask A Question and perhaps even I know what I mean. Why don't you?.

        -code to answer the question.

        But that doesn't answer the question because we cannot duplicate the data stream from the  $sock handle. All we can do is fake some data by assigning a string to the  $input or  $str variables — as you did in the example code in your OP and I did in my original reply.

        It seems likely that you aren't getting the data in the exact format you're expecting. Try adding some debugging lines:

        while (my $input = <$sock>) { print "input line: **start**$input**end**\n"; # debugging if (index($input, "/QUOTE") != -1) { print " is a match\n"; # debugging my $str = $input; ($pass) = $str =~ m{/QUOTE\sPASS\s(.*?)$}; print $sock "QUOTE PASS $pass\r\n"; } else { print " not a match\n" # debugging } }

        One thing I notice is that you're both reading from and writing to the filehandle in $sock. That might be possible if that's a particular kind of object, but it definitely won't work if it's a normal pipe or filehandle, so it might be a mistake.

        Aaron B.
        Available for small or large Perl jobs; see my home node.