In your example, I think you mean to use a character class, $agent =~ /[A-Z]/. Applying that to your question, you want to use the substitution operator:
Taking that apart, the parens store the matched character in $1. A space followed by the value of $1 is substituted. The g flag is for global, it make the substitution apply all through the string..$agent = 'PerlBeginnerPerl'; $agent =~ s/([A-Z])/ $1/g;
This will insert a leading space if the first character is capitol. To avoid that we can use a more sophisticated gadget. The additional element is a negative lookbehind assertion that we're not at the beginning of the string:
$agent =~ s/(?<!^)([A-Z])/ $1/g;
Update: (Assuming my reading of the question was correct) The second version can be converted to capture nothing by using positive lookahead for the capitol letter:
This does the insertion by looking at the surroundings of the notch before a character, and inserting a space if conditions warrant.$agent =~ s/(?<!^)(?=[A-Z])/ /g;
After Compline,
Zaxo
In reply to Re: Search for a character in CAPS
by Zaxo
in thread Search for a character in CAPS
by c_lhee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |