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 |