Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Re: Store regex modifiers in variables?

by smferris (Beadle)
on May 15, 2002 at 16:06 UTC ( [id://166766]=note: print w/replies, xml ) Need Help??

in reply to Re: Store regex modifiers in variables?
in thread Store regex modifiers in variables?

I was looking for a similar issue. My problem wasn't with a match, but a substitution. This node is fairly old, however very relevant to my problem and I'm adding my comments in case someone needs a similar answer.

<bold>Project details:</bold>
I'm building a "interactive shell" to make our life easier. (DBA Group) In one shell I plan to tie Oracle, Sybase (DBI) and Sybase Replication together. Replication is also managed via DBI, but I provide a customized syntax for manipulating it. (They don't provide bulk loading functionality for heterogeneous environments. Thats done via other Perl scripts/modules) ;) I wanted to provide the user with a way of manipulating the input "buffer" via regex.

The only modifiers I allow are i,s,m & g for simplicity. ('e' & 'm' would be more difficult to "grammerize" than I'm willing to spend time on) While i,s & m are fine using the syntax (?$mods), I don't believe the g is. Well, no big deal.. My solution:

if ($mods=~s/g//g) { $buffer=~s/(?$mods)$expr1/$expr2/g; } else { $buffer=~s/(?$mods)$expr1/$expr2/; }

Hope this helps someone else, like myself! Great thread, thanks to all!

SMF 8)

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-05-30 19:43 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.