qr//e?

Chris Radcliff chris_radcliff at mac.com
Fri Apr 23 16:54:20 CDT 2004


~sdpm~
I couldn't articulate why it's a Good Idea, but /e only applies to the 
right side of a substitution.

In your case, are you hoping to re-evaluate the join() each time you 
use the compiled expression (e.g. if @days were to change for some 
reason)?

If so, it's not likely to work the way you think it will, at least in 
the first of the two "ugly" cases. (Not sure about the second case. 
Will qr// create a closure with the local $"?)

If not, why not just do this:

my $days = join '|', @days;
my $days_re = qr/$days/;

...which seems to do the same as your do block. Remember that qr *will* 
evaluate variables unless you're using /Q$things/E, so you don't need 
any modifiers to get this behavior.

Cheers,
~chris (off the top of me 'ead)

On Apr 23, 2004, at 2:15 PM, Tkil wrote:

> ~sdpm~
>
> Fellow mongers:
>
> Can anyone think why /e might be a bad idea to suggest for addition to
> the qr// operator?
>
> I found myself doing something like this, the other day:
>
>    my @days    = qw( Sun Mon Tue Wed Thu Fri Sat );
>    my $days_re = qr/join '|', @days/e;
>
> And I was startled to discover that qr doesn't have a /e flag.
> Granted, it has only ever been in the substitution part of s///, but
> this seems pretty straightforward.  There are obvious workarounds:
>
>    my $days_re = do { my $tmp = join '|', @days; qr/$tmp/ };
>
> Or, in this particular case, something almost as ugly:
>
>    my $days_re = do { local $" = '|'; qr/@days/ };
>
> Still, it seems that /e might be entirely useful on qr//.  Anyone have
> examples or counter-examples that come to mind?
>
> t.
> ~sdpm~

~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list