Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^3: IRC Client not Joining Channel

by assemble (Friar)
on Mar 04, 2008 at 17:35 UTC ( #671951=note: print w/replies, xml ) Need Help??

in reply to Re^2: IRC Client not Joining Channel
in thread IRC Client not Joining Channel

I recommend cutting out all the extra code next time, it is very distracting from the actual problem. So here is the code that you say appears to be bad
#-------------------Watch for IRC Inputs------------------- sub incoming_data { my ( $fd, $condition, $fh ) = @_; print "its going\n"; if ( $condition eq 'in' ) { my $input; sysread $fh, $input, 1000000; #chop $input; $input =~ s/\r\n//g; my $hashref = $parser->parse( $input ); SWITCH: { my $type = lc $hashref->{command}; my @args; push @args, $hashref->{prefix} if $hashref->{prefix}; push @args, @{ $hashref->{params} }; if ( defined $dispatch{$type} ) { $dispatch{$type}->(@args); last SWITCH; } print STDOUT join( ' ', "irc_$type:", @args ), "\n"; } } return 1; }
First, I recommend changing:
sysread $fh, $input, 1000000; #chop $input; $input =~ s/\r\n//g;
$input = <$fh>; chomp $input;
You can put a loop in there if you want to handle more than one line at a time. What you are doing mushes everything together and makes it unparseable.

Replies are listed 'Best First'.
Re^4: IRC Client not Joining Channel
by deadpickle (Pilgrim) on Mar 04, 2008 at 19:47 UTC
    It seems that the Gtk2::Helper is not running after the connection is made. The print in incoming_data "im going" does not appear so it seems like the Helper is not working.
    sub connecting { # Connect to the IRC server. $sock = new IO::Socket::INET( PeerAddr => $irc, PeerPort => 6667, Proto => 'tcp', ) or die "Can't connect\n"; print "hello\n"; $watch = Gtk2::Helper->add_watch( fileno $sock, 'in', \&incoming_d +ata, $sock ); # Log on to the server. print $sock "NICK $nick\r\n"; print $sock "USER $login 8 * :CoCoNUE Member\r\n"; $chat_entry->set_editable(1); $chat_entry->grab_focus; #chat_entry->signal_handler_unblock ($chat_send_sig); return 1; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://671951]
[Eily]: you could tie a variable into not having the same value each time, if you like to make people who try to debug your code facepalm
[Corion]: perl -wle 'package o; use overload q("") => sub {warn "str"; ""}, bool => sub{warn "bool"; 1}; package main; my $o={}; bless $o => o; print "Yay" if ($o && !length($o))'
[Corion]: But people writing such code should document the objects they construct and why it makes sense for an object to be invisible as string while being true in a boolean context
[hippo]: That's equal parts clever and horrendous.
[Eily]: the overload version wouldn't return true with "$x" && !length $x though, I guess
[hippo]: The more I look at this code, the more $x is a plain old scalar and the more this condition will never be true. I'm calling it a bug at this point.
[hippo]: Thanks for your input which has soothed my sanity (a little)
[Corion]: Eily: Sure - if you force both things into stringy things, then you break that magic. But that would also mean that you changed the expression, as now $x = 0.00 will be true instead of false as it were before
[Corion]: Ah no, at least in my feeble experiments that doesn't change the meaning
[Corion]: We sell sanity in small packages ;)

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2017-07-27 13:42 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (413 votes). Check out past polls.