Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: regex not working..

by AnomalousMonk (Archbishop)
on May 12, 2012 at 17:35 UTC ( [id://970199]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^4: regex not working..
by Anonymous Monk on May 12, 2012 at 17:52 UTC
    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://970199]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found