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

Re: [MacPerl] passing regexp to routine



On Mon, 8 Jun 1998, John Deighan wrote:
> 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:
[snip]

A simple and dirty way to do that :

read_until('#EOF');

sub read_until {
  my $pat = shift;
  $line = <STDIN>;
  while($line !~ m/$pat/) {
    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?

It is possible using the Perl prototypes, but I don't remember how exactly. 
This is explained in the Camel Book, and probably in some FAQs. 


Sebastien Aperghis-Tramoni           mailto:Sebastien.Aperghis@esil.univ-mrs.fr
                                     mailto:madingue@cis.uni-muenchen.de
http://www.resus.org/~madingue       mailto:madingue@tango.resus.univ-mrs.fr
----------                                                           ----------
Perl has no bug : only unexpected or unwished features.


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