hey,
i have been using the expression
(?<!\\)\$[a-zA-Z0-9_]+
to match all variable names in a perl script, except those whose name is escaped (
"\$blah"), and it works fine, but i wanted to turn it into a substition (the script is supposed to change variable names in a perl script) and have each instance of a variable replaced with the output of a subroutine which accepts the matched text as it's argument and mixes the characters around...however, i tried
s/(?<!\\)\$[a-zA-Z0-9_]+/change_name($&)/ge
and it didnt seem work. (i understand '$&' holds the last matching text..and after reading some example code, i also tried '$1'...to no avail)..the code segment is
while (<FILENAME>) {
s/(?<!\\)\$[a-zA-Z0-9_]+/change_name($&)/ge;
}
and change_name()'s return value is the altered text.
thanks in advance,
moe
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.