Arun wrote: > > Hi this is Arun here, i am new to perl.Here i am trying to read a > string from the serial port but i am not able to and this is my > program: > > # Read serial port until message or timeout occurs > sub ReadPort($$$) { > (my $String, my $TimeOut, my $Display) = @_; > $ob->read_const_time($TimeOut); # Setup timeout value in mS > my $Reply = ""; # Initialize message > do { > ($Count, $Result) = $ob->read(1); # Read serial port > $Reply .= $Result; # Build message > print "$Result" if ($Display); # Display messages if enabled > } while($Count > 0 and $Reply !~ m/$String/); > print "\n" if ($Display); # Put carriage return at end of > displayed output > if ($Reply !~ m/$String/) { > print "ERROR: Read timed out waiting for '$String' \n"; > return(1); > } > return($Reply);
You shouldn't use prototypes for Perl subroutines: they don't do what you think they do, and they are more likely to break things than be useful. Unless you have your own reasons for naming your variables with mixed case, many people would thank you if you changed to using all lower-case. Names beginning with a capital letter are usually package or module names. What problem are you having? It looks basically alright to me, although it may not be wise to use the value of $result if $count is zero. How about a loop like this: { my ($count, $result) = $ob->read(1); last unless $count; print $result if $display; $reply .= $result; redo unless $reply =~ /\Q$string/; } HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/