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

Re: [MacPerl] passing regexp to routine



At 20.31 +0200 98-06-08, John Deighan wrote:
>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?

You can assign a string to a variable and use it in a regex:

read_until('#EOF');

sub read_until {
   my $regex = shift;
   while (<>) {
      last if /$regex/;
      # Do whatever you want to do
   }
}

The problem with this is that the string has to be compiled into an
internal regex structure - I guess there is a faster way to do it.


___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