|
|
Perl Substitution - Perl
|
Views : 288
|
|
Tagged in : Perl
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
Perl Substitution
The syntax s/match_value_to_replace/replace_value/ replaces the value searched for with the replace_value. By adding the letter g to the end, will find all possible matches. Otherwise, only the first match found is changed.
$_ = "here where there theresa";
s/ere/at/g; # $_ = hat, what, that, thatsa
$_ = "hello, world";
$new = "goodbye";
s/hello/$new/; # $_ = goodbye, world
$_ = "this is a test";
s/(\w+)/<$1>/g # $_ =
The above works, because $1 is set to the with in the first parenthesized pattern match, which is this case is each word because the 'g' flag is used. |
|
By Geethalakshmi, On - 2010-09-17 |
|
|
|