Results 1 to 4 of 4

Thread: Sustitution in Perl.

Threaded View

  1. #1
    Join Date
    Jan 2008
    Beans
    4,756

    Sustitution in Perl.

    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
    Last edited by ibuclaw; May 13th, 2008 at 04:36 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •