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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.