in reply to regex "o" modifier

You can use eval and /o together for rise of performance:
for my $day_week( qw(Mon Tue Wed Thu Fri Sat Sun) ) { my $regexp = "^$day_week"; eval 'for my $day (qw (Mon Mon Wed Fri Sat Sun Fri Wed Tue Wed) ) +{ if($day =~ m/$regexp/o) { # do somthing } }'; }
In this case, regexp will be recompiled for each iteration of extern loop, which changes our regexp. But the regexp will not recompile every time into internal loop. It will serve.
      
--------------------------------
SV* sv_bless(SV* sv, HV* stash);

Replies are listed 'Best First'.
Re^2: regex "o" modifier (use qr//)
by Aristotle (Chancellor) on May 07, 2003 at 07:46 UTC
    That's a perfect example of what qr// was made for.
    for my $day_week( qw(Mon Tue Wed Thu Fri Sat Sun) ) { my $regexp = qr/^$day_week/; for my $day (qw (Mon Mon Wed Fri Sat Sun Fri Wed Tue Wed)) { if($day =~ m/$regexp/) { # do somthing } } }
    Much clearer and more readable and, yes, more efficient too. tye is right: Never use /o.

    Makeshifts last the longest.