Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

can regex contains function?

by toothedsword (Sexton)
on Jun 19, 2020 at 07:11 UTC ( [id://11118253]=perlquestion: print w/replies, xml ) Need Help??

toothedsword has asked for the wisdom of the Perl Monks concerning the following question:

can regex contains function? I want convert the first character of words upcase. The code below does not work.

#!/usr/bin/env perl my $t = ' aa bb cc'; $t =~ s/(\s)(\w)/${1}uc($2)/g; print($t);

Replies are listed 'Best First'.
Re: can regex contains function?
by choroba (Cardinal) on Jun 19, 2020 at 07:49 UTC
    > can regex contains function?

    Yes, it can. That's what /e is for.

    $t =~ s/(?<=\s)(.)/uc $1/ge;

    But you don't need it here:

    $t =~ s/(?<=\s)(.)/\U$1/g;

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: can regex contains function?
by soonix (Canon) on Jun 19, 2020 at 07:29 UTC
      Thank you so much! Now I know how to solve this specific question. But do you know can I instert a function to the regex?

        If I understand your question, the first responder answered it: use the /e qualifier.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11118253]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-28 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found