Hi all.
Quick question:
How do I substitute strings while printing them in perl? (ie: WITHOUT appending the change to the string).
ie:
BASH Example
Code:
export rhyme="baabaablacksheep" # assign string to variable.
printf "%s\n" "$rhyme" # print string.
printf "%s\n" "${rhyme##baabaa}" # remove baabaa from string.
printf "%s\n" "${rhyme/baabaa/foobar}" # replace baabaa with foobar.
printf "%s\n" "${rhyme//b/k}" # replace all matches of b with k.
printf "%s\n" "$rhyme" # print string again.
Will produce the output:
PHP Code:
baabaablacksheep
blacksheep
foobarblacksheep
kaakaaklacksheep
baabaablacksheep
Without altering the original string.
Any help would be appreciated.
Regards
Iain
Bookmarks