List Info

Thread: substitution + backreferences + function call




substitution + backreferences + function call
country flaguser name
United States
1969-12-31 18:00:00

Hey all,

Just wondering syntactically how to use a function within the
substitution operator. I'm essentially iterating through a series of
keywords and trying to uppercase them:

my keywords = qw(select from where in between having group order by
left right join);
$_ = $sql;
for my $keyword(keywords){
s/b($keyword)b/$1/gi;
}
$sql = $_;

but when I try to use:
s/b($keyword)b/uc $1/gi;

I'm getting a literal "uc" rather than the results of the function. Any
suggestions - is my approach a sound one?

__._,_.___
.

__,_._,___
Re: substitution + backreferences + function call
country flaguser name
United States
1969-12-31 18:00:00

>>&gt;>> "da5id" == da5id < da5id%40t3rse.com">da5idt3rse.com> writes:

da5id>; but when I try to use:
da5id> s/b($keyword)b/uc $1/gi;

da5id> I'm getting a literal "uc&quot; rather than the results of the function. Any
da5id&gt; suggestions - is my approach a sound one?

Well, for "uc&quot; specifically, you can use U:

s/b($keyword)b/U$1/gi;

But in general, you can use /e, as in:

s/b($keyword)b/uc $1/gie;

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<; merlyn%40stonehenge.com">merlynstonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

__._,_.___
.

__,_._,___
Re: substitution + backreferences + function call
country flaguser name
United States
1969-12-31 18:00:00

> you can use U: s/b($keyword)b/U$1/gi;

Very cool - I like the option of using e as a regex evaluation option
since I can envision myself needing to evaluate a lot as I do the
substitution. I looked in the Llama book and didn't see this but then
found a reference in Freidl's Mastering Regular Expressions although it
missed a complete list. He called it a Case-Folding Span. Are 1 and U
the only ones of these?

Thanks much,

David

Randal L. Schwartz wrote:
&gt;>>>>>; "da5id" == da5id < da5id%40t3rse.com">da5idt3rse.com> writes:
>>>;>>&gt;
>
> da5id> but when I try to use:
>; da5id> s/b($keyword)b/uc $1/gi;
&gt;
> da5id> I'm getting a literal "uc&quot; rather than the results of the function. Any
> da5id> suggestions - is my approach a sound one?
>;
> Well, for "uc&quot; specifically, you can use U:
>
> s/b($keyword)b/U$1/gi;
>
> But in general, you can use /e, as in:
>
> s/b($keyword)b/uc $1/gie;
>
>

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )