Whats wrong with: ... s/(?<=__)(A-Z_)+//g;
Nothing (other than not needing the g modifier :-) but as I said, there are a lot of ways to tackle the problem and this particular question piqued my interest. I have tried accessing pos() inside the while loop but I get "Use of uninitialized value" warnings. Doing the same with a match rather than a substitution seems fine and I can even assign to pos() to affect where it matches.
#!/usr/bin/perl -l
#
use strict;
use warnings;
$_ = q{DFR7234C__A_B_C_Bonzo_Dog_D_B};
print;
while ( s{(?<=__)[A-Z]_}{} )
{
print pos();
}
print;
print q{-} x 25;
# ---------------------
$_ = q{DFR7234C__A_B_C_Bonzo_Dog_D_B};
print;
while ( m{_}g )
{
print pos();
}
print q{-} x 25;
# ---------------------
$_ = q{DFR7234C__A_B_C_Bonzo_Dog_D_B};
print;
while ( m{_}g )
{
print pos();
pos() = 23 if pos() >= 12 && pos() < 26;
}
print q{-} x 25;
# ---------------------
produces
DFR7234C__A_B_C_Bonzo_Dog_D_B
Use of uninitialized value in print at ./spw644148G line 11.
Use of uninitialized value in print at ./spw644148G line 11.
Use of uninitialized value in print at ./spw644148G line 11.
DFR7234C__Bonzo_Dog_D_B
-------------------------
DFR7234C__A_B_C_Bonzo_Dog_D_B
9
10
12
14
16
22
26
28
-------------------------
DFR7234C__A_B_C_Bonzo_Dog_D_B
9
10
12
26
28
-------------------------
I agree with you, oha's solution is very nice indeed. Thank you for your reply, JohnGG
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, 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, 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.
|
|