On Fri, 03 Nov 2017 15:12:15 -0500 "Martin McCormick" <marti...@suddenlink.net> wrote: > What is needed, however, is to be able to use the are_match > feature which fills a buffer with data until a pattern is > detected which stops the read and gives you a series of bytes > that may not necessarily end with a newline or carriage return. > > I have never yet gotten anything like the following to > work: > > #!/usr/bin/perl -w > use strict; > #use warnings::unused; > use File::Basename; > use File::Copy; > use File::Spec; > use Time::Local; > use Device::SerialPort; > > sub comm { #serialport > > my $dev = "/dev/ttyS0"; > my $c = ""; > my $port = Device::SerialPort->new("$dev"); > $port->baudrate(9600); $port->databits(8); $port->parity("none"); > $port->stopbits(1); $port->handshake("none"); > $port->write_settings; > > until ("" ne $c) { > my $c= $port->lookfor; > print ("$c\n") if $c; > } > return; > } #serial port [...] > I have tried it with and without an are_match pattern and > it just roars along, looping endlessly at the lookfor statement > and never picking up anything.
Instead of assigning the result of $port->lookfor to $c, you've created a new lexically-scoped $c (with "my $c") which exists only within that loop body execution - after the execution, it goes away, and the $c the loop is looking for, at a higher scope, will still be empty. I imagine things might change if you remove the "my" from that assignment, so that you're assigning the result to the $c that the loop condition is looking at. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/