[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] passing regexp to routine



At 17.47 +0200 98-06-10, John Deighan wrote:
>sub read_until { my($endpat) = @_;
>$line = <STDIN>;
>if ($line !~ /$endpat/) {
>	print $line;
>	$line = <STDIN>;
>	while ($line !~ //) {
>		print $line;
>		$line = <STDIN>;
>		}
>	}
>}
>
>Does anyone see a problem with this solution

Yes.

The null pattern (//) means the last successfully executed pattern. In the
above subroutine, the null pattern is never used if the /$endpat/ pattern
succeeds.

If the first line doesn't match /$endpat/, the // pattern is used, but
since there is no successfully executed pattern, it won't match, and the
subroutine will return after printing the first line.

To make the solution work, you must make a pattern that will succeed on the
first line - as I did previously.


___Carl_Johan_Berglund_________________________
   Adverb Information
   carl.johan.berglund@adverb.se
   http://www.adverb.se/



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch