in reply to Use global flag when declaring regular expressions with qr?

Hello and welcome to the monastery unmatched,

as I told you in the cb, better the question better answers.. and it happened :)

as was not mentioned you can also do:

# $opts = 'g'; DONT WORK # $rex = eval qq(qr/here/$opts);

See also: /o is dead, long live qr//! and Use global flag when declaring regular expressions with qr?

L*

UPDATED because it doesnt work with g ..sorry for the noise

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Use global flag when declaring regular expressions with qr?
by ysth (Canon) on Oct 29, 2024 at 12:33 UTC
    Gives:
    Unknown regexp modifier "/g" at (eval 1) line 1, at end of line
    As mentioned elsewhere, g is one of the flags that is a property of the match/substitution operator, not of the regex, and can't be used with qr.
    --
    A math joke: r = | |csc(θ)|+|sec(θ)| |-| |csc(θ)|-|sec(θ)| |
Re^2: Use global flag when declaring regular expressions with qr?
by ikegami (Patriarch) on Oct 29, 2024 at 11:29 UTC

    If you're building a match or substitute operator, generally better to use String::Substitution than eval.

Re^2: Use global flag when declaring regular expressions with qr?
by unmatched (Sexton) on Oct 29, 2024 at 12:07 UTC

    Thank you, Discipulus! You were absolutely right, I tried to make a best question as I could to not be too lengthy but also avoid the back and forth of asking for more details, etc. And I have to say that I'm very grateful for the many replies and useful tips!