markcsmith has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I once saw a post on how to write something like this:
$a = "blah bla blah"; $b = $b; $b = s!blah (bla) blah!$1!;
in one line instead of 3. Is my memory decieving me, or is this really possible? I'm tired of the clukniness that the former method requires. Thanks!

Mark

Replies are listed 'Best First'.
Re: simple replace
by belg4mit (Prior) on Sep 20, 2002 at 18:34 UTC
    ($b = $a = "blah bla blah") =~ s!blah (bla) blah!$1!;
    PS> I don't recommend the use of $a and $b due to their special meaning for sort.

    --
    perl -pew "s/\b;([mnst])/'$1/g"

Re: simple replace
by Anonymous Monk on Sep 20, 2002 at 18:36 UTC
    What are you trying to swap? Your code is unclear to me, more specifically: "$b = $b"

    You can do a simple replace with a regex like:

    $a = "blah bla blah"; $b =~ s/$a/$replacement_string/;
Re: simple replace
by csotzing (Sexton) on Sep 20, 2002 at 18:40 UTC
    I think you're asking if there's a shortcut for:
    $a = "blah bla blah"; $b = $a; $b =~ s/blah (bla) blah/$1/;
    If so, how about:
    $a = "blah bla blah"; ($b) = $a =~ /^\S+\s+(\S+)\s+\S+$/;

    print(map(lc(chr),split(6,qw/99672682673683684689632658645641610607/)));