All pastes #199644 Raw Edit

Untitled

public text v1 · immutable
#199644 ·published 2006-10-12 17:39 UTC
rendered paste body
Here is the code:

#!/usr/bin/perl -wie

my $foo = "john jacob jingleheimerschmidt";
my $replacement = "bob";
my $line = "john jacob jingleheimerschmidt";


if($line =~ m/(john\s)(jacob\s)(jingleheimerschmidt)/ ){
        print "\$replacement = $replacement\n";
        print "\$2 = $2\n";
        print "\$3 = $3\n";
        $newline = $replacement . $2 . $3;
        print "\$newline = $newline\n";
        s/$line/$newline/ex;
}

print $foo;


Here is the output:

./test.pl
$replacement = bob
$2 = jacob
$3 = jingleheimerschmidt
$newline = bobjacob jingleheimerschmidt
Use of uninitialized value in substitution (s///) at ./test.pl line 14.
john jacob jingleheimerschmidt