Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: /o is dead, long live qr//!

by Anonymous Monk
on Jun 26, 2003 at 12:01 UTC ( #269204=note: print w/ replies, xml ) Need Help??


in reply to /o is dead, long live qr//!

What about this:

use constant foo => 'bar'; my $x = qr/ ${\&foo} /xo; "something" =~ $x;
I found this to be the only way I could achieve this effect. Is there a better way?


Comment on Re: /o is dead, long live qr//!
Download Code
Replies are listed 'Best First'.
Re: Re: /o is dead, long live qr//!
by diotalevi (Canon) on Jun 26, 2003 at 12:08 UTC

    Yes and? Your qr// expression interpolated and then fixed the constant into place. Normally I'd just eschew that as a particularly ugly form of a regex though. In fact, I'd likely have written that as this instead. I'd be using the constant like its intended (as in, not like a cleverly named function) and I still get something reasonable. Now other people like Perrin have been convincing me that constant isn't all that great anyway especially given the bareword quoting rules with the => fat comma and interpolation (like you noticed).

    use constant FOO => 'bar'; my $x = FOO; $x = qr/$x/; "somehting" =~ $x

    So actually, I wouldn't have written it at all like that. This is more likely. Though I wouldn't have gone out of my way to create a qr// object if I was only going to use it in one place anyway. That looks like something that'd be better written as merely "something" =~ $FOO.

    our $FOO = 'bar'; my $x = qr/$FOO/; "something" =~ $x;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://269204]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2015-07-07 23:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls