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

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..

Replies are listed 'Best First'.
Re^5: regex not working..
by Corion (Patriarch) on May 12, 2012 at 18:00 UTC

    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?

Re^5: regex not working..
by AnomalousMonk (Archbishop) on May 12, 2012 at 18:16 UTC
    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.

Re^5: regex not working..
by aaron_baugher (Curate) on May 13, 2012 at 01:38 UTC

    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.