You know, this response is itself enough to make me agree that qr//e is a bad idea. Thanks for taking the time to beat it into my thick skull. I now think that true eval is overkill.

(Although, to be fair, the issues you bring up are already solved for the replacement text in s///e, are they not?)

Having said that, can you think of a syntax that would express my intent of applying qr to a value that is generated some way other than double-quote or regex interpolated? My original examples, for reference:

my @days = qw( Sun Mon Tue Wed Thu Fri Sat ); my $days_re = do { my $tmp = join '|', @days; qr/$tmp/; }

Using some of the other ideas that have cropped up, I could perhaps just do this:

sub compile_regex ( $ ) { qr/$_[0]/; } my $days_re = compile_regex join '|', @days;

Although I still like the cuteness factor of doing it this way:

my $days_re = qr->( join '|', @days );

Too bad that breaks valid code.


In reply to Re: Re: Re: Re: qr// with /e? by tkil
in thread qr// with /e? by tkil

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.