Re: Prepend + to search words



Grant wrote:
Hello, how can I prepend a "+" character to each of the words in a
string? For example, "big blue widgets" should be changed to "+big
+blue +widgets".

I'd probably use an s/// (substitution) on the string. Match a word,
replace it with the plus sign and the word. Have you tried that?

Hi Tom,

I just had a look at some docs matching "perl substitution variable"
since the words in the string could be anything, but perl docs have a
way of overwhelming me really quickly. Can you show me how?

$ perl -le'$_ = "big blue widgets"; print; s/(\w+)/+$1/g; print'
big blue widgets
+big +blue +widgets



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.



Relevant Pages

  • Re: Prepend + to search words
    ... I'd probably use an s/// (substitution) on the string. ... I just had a look at some docs matching "perl substitution variable" ... (see perlretut and perlre) ...
    (perl.beginners)
  • Re: Escape $ in replace pattern: How to replace pattern "a*c" by exact string "p$1q&q
    ... > jakarta ORO Regex package which uses Perl5 internally. ... > a perl pattern for the search string and replace string. ... (I am assuming here that another similar substitution did actually ...
    (comp.lang.perl.misc)
  • Re: Prepend + to search words
    ... I'd probably use an s/// (substitution) on the string. ... I just had a look at some docs matching "perl substitution variable" ... way of overwhelming me really quickly. ...
    (perl.beginners)
  • Re: Need help editing a string
    ... I want to delete the last character in the string if it is a '/'. ... This is basically a pattern matching and substitution problem. ... The book I mostly learned perl from is called Little Black Book, ...
    (perl.beginners)
  • Re: Question on regex substitution using variables...
    ... back-substitution, and just prints "$1.def". ... Once you have put a literal $ into a string, ... substitution as a little code block and have it evaluated: ... This being Perl, I await news of the 1867 other ways to do it... ...
    (comp.lang.perl)