in reply to Re^2: updating a variable call in a hash table
in thread updating a variable call in a hash table

I guess here's an even simpler example:
$color = "green"; $text = "The color is $color" $color = "blue"; print $text;
I want the output to be "The color is blue". How do I make that happen?

Replies are listed 'Best First'.
Re^4: updating a variable call in a hash table
by GrandFather (Saint) on Feb 09, 2009 at 03:50 UTC

    It doesn't matter where your template string comes from, it's still a string containing some markup.

    It's the same question with the same answer: use a templating system. Consider:

    use warnings; use strict; for my $color (qw(green blue red puce)) { my $text = "The color is COLOR\n"; $text =~ s/COLOR/$color/g; print $text; }

    prints:

    The color is green The color is blue The color is red The color is puce

    Perl's payment curve coincides with its learning curve.