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

[MacPerl] passing regexp to routine



I would like to write a routine (function, whatever) that reads input until
it encounters a line that matches a particular pattern. To do that, I'd
like to pass a regular expression to a routine. Is that possible? I tried
it in the obvious way, and it didn't work:

read_until(/#EOF/);

sub read_until { my($endpat) = @_;
$line = <STDIN>;
while ($line !~ $endpat) {
	print $line;
	$line = <STDIN>;
	}
}

I guess the more basic question might be, can you assign a regular
expression to a variable and later use it to do pattern matching?

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