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

Re: checking particular part of string

by vinoth.ree (Parson)
on Mar 07, 2014 at 13:35 UTC ( #1077378=note: print w/ replies, xml ) Need Help??


in reply to checking particular part of string

Hi sumandas,

In your code you no need to use $str =~ m/na/ you can directly use the $str =~ s/na//gi; code, as you need to check the "na" string to be matched at the end of the srtring, perl has the special chater "$" used to match at the end of the sctring, so $str =~ s/na$//gi; this will match the "na" at the end of the string, now u want that "na" at the end of the string to be converted to UPPERCASE "na", so we need to get the same substring to replace, so we need to group it, as $str =~ s/(na)$/uc($1)//gi;, the grouped string will be available in $1 special variable, and use the uc() BIF to convert the matched substring to uppercase.


All is well


Comment on Re: checking particular part of string
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-12-25 12:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls