in reply to substitution not recompile

The first time the substitution is executed you lose your x in $foo; next times, there's no x to substitute. You're probably looking for:
$template = "some sentence x"; $val = 1; while ($val < 5) { $foo = $template; $foo =~ s/x/$val/; print "$val $foo\n"; $val++; }
Flavio

-- Don't fool yourself.

Replies are listed 'Best First'.
Re^2: substitution not recompile
by manav (Scribe) on Mar 24, 2005 at 15:30 UTC
    Or maybe
    $template = "some sentence x"; for $val (1..4) { ($foo = $template) =~ s/x/$val/; print "$val $foo\n"; }


    Manav