Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Match strings that contain uppercase letters

Status
Not open for further replies.

CJason

Programmer
Oct 13, 2004
223
0
0
US
I have a line of text...say:

"My.File, your.File, another.file, SOMEBODY.file"

I want to "loop" thru the line, grabbing each filename (in this example) that contains an uppercase letter, and do something with that word.

For example:
Code:
$changed = 1;
while ($changed) {
  $changed = 0;
  if (/(\w+\.\w+)/) {
    $text = $1;
    print "$text\n";
    $lctext = lc($text);
    s/$text/$lctext/g;
    $changed = 1;
  }
}

As you can see, this would result in an infinite loop because it's always grabbing the same filename. HOWEVER, if I am able to somehow specify that I only want to match (\w+\.\w+) where there is an uppercase letter in it...all is good.

Any ideas?
 
Is there other data in the line you don;t want to change to lower-case? Because it looks like you can just change the entire line to lower-case since its all "word.word".

Maybe you would be better off splitting the line on the commas and examining each token individually.


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Is there other data in the line you don;t want to change to lower-case? Because it looks like you can just change the entire line to lower-case since its all "word.word".

Maybe you would be better off splitting the line on the commas and examining each token individually.


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Sorry, I just simplified it for "question asking" purposes. Yes, please assume the following:

1) there is more on the line that I don't want to lowercase
2) there is no set token, like commas, that can be split on

The only thing I want to touch is things in the form:
Code:
 /\w+\.\w+/

FYI: I've run into this type of scenario before, and what I've done in the past is using a "string position pointer" to look at "the rest of the line" instead of the entire line. But, I would prefer to just keep checking the entire line over and over again...if that's possible.
 
$_ = "My.File, your.File, another.file, SOMEBODY.file";
s/(\w+\.\w+)/lc($1)/eg;
print;
 
The solution for what I think you want to do is simple, see brigmars post. Your complicated code makes me think you are trying to do something more than what you have described, if not, then brigmars solution will do the trick.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Sorry, Kevin...yes, I was making it way too hard. Thanks guys!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top