Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Net::IRC and IO::Socket

by btrott (Parson)
on Jun 20, 2001 at 10:03 UTC ( #89927=note: print w/replies, xml ) Need Help??

in reply to Net::IRC and IO::Socket

Two "monopolistic" processes can share, and that sharing is done through the use of select; select is used to wait on a set of sockets, and to pass control back to you when at least one of those handles is "ready". However "ready" is defined: for example, you may be waiting for the socket to be have data that can be read from it; or you could be waiting for the socket to be ready for writing, etc.

In this case, it's slightly tricky, because you want to intermix a socket "contained" by Net::IRC and one that you're using in your own application. After a look at the Net::IRC docs, it looks like you might be able to use the 'addfh' method to add your UDP socket handle to the list of handles in the select loop that is entered when you call the 'start' method.

When you use 'addfh', it looks like you give Net::IRC a filehandle, a callback function to call when the handle is "ready", and a flag saying what kind of handle this is (reading/writing/error).

So, in other words, you might do something like this (note: untested)--

$irc->addfh($socket, \&has_data, "r"); $irc->start; sub has_data { my $socket = shift; $socket->recv(my $data, 1024); ## Now trigger some Net::IRC event based on $data }
Note that you may need to investigate the exact args that get passed to your callback function; I'm not sure if the filehandle is the only thing passed. Note also that you'll need to get the Net::IRC object somehow, I believe, in order to send an event based on $data; one way to do this would be to create the callback function as a closure.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://89927]
[Corion]: Cosmic37: Ah, see perlfaq4, about How do I compute the intersection of two arrays
[Cosmic37]: I am out of practice; I use Perl for scientific programming for number crunching
[Corion]: Cosmic37: Basically, you read one file into a hash, keyed by your key, and then match the lines from the second file to that hash
[Cosmic37]: note that the two files only have datetimes which may match whereas other data per line is different format in file1 and file2 - is that really intersection?
[jedikaiti]: Hi Monks
[Corion]: Cosmic37: Well, if you want to use only parts of a line for the key, see split or whatever other mechanism to extract the key from the line
[Corion]: Hi jedikaiti!
[Cosmic37]: is there a webpage for full CB for this chat rather than side panel chat?
[Cosmic37]: thank you for advice
[Cosmic37]: peach greets jedi

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2017-06-29 16:21 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (672 votes). Check out past polls.