sub is_serial_data_ready { print "is_serial_data_ready: enter\n"; # Non-blocking read: otherwise, we'll hang up here! my $c = $port->input; print "is_serial_data_ready: got <$c>\n"; # Process the incoming characters for my $char (split '', $c) { print "is_serial_data_ready: char '$char'\n"; if ($char eq "\n" or $char eq "\r") { print "is_serial_data_ready: end-of-line found\n"; # End of line found, add current line to buffer # (unless it's empty) if ($serial_input ne '') { push @serial_data, $serial_input; # start a new blank line $serial_input = ""; } } else { # Just a normal character, add to the input $serial_input .= $char; } } # Returns true if there are any completed lines to handle print "is_serial_data_ready: ", join(" // ", @serial_data), ".\n"; return scalar @serial_data; }