Hi, I am accessing the serial port through perl script, I am trying to detect some pattern in the incoming serial port data (lets say i am trying to find "abcd" in incoming serial port data like "zcfgsdbabcdppuahjajg") and till the pattern is detected i want to execute some command using until loop in perl and once the pattern is detected the perl script should come out of the loop and should execute the next command after the loop. But after detecting the pattern the perl script is executing the command inside the loop one more time. How can i stop the execution of the loop and come out of it after the pattern detection and send next command? Here is the code that i am using..
#!/usr/bin/perl use Win32::SerialPort; $PortObj->are_match("abcd"); # Pattern to match my $gotit = ""; until ("" ne $gotit) { $gotit = $PortObj->lookfor(); # Look for the pattern "abcd" in the inc +oming data if($gotit){last;} # to exit the loop after the pattern detection print("Pattern is not detected\n"); # print the message till pattern i +s detected. # send some command through serial port in loop till the pattern is de +tectd } # send next command after the pattern detection.
In reply to pattern detection inside until loop in perl by vrushali
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |