in reply to Transfering Varriables
You will need to adapt this to make it more robust and to make it fit your need but this should give you the general idea.#!/usr/bin/perl -w use strict; my %values; # Pretend we have an input file w/values while (<DATA>) { last if /TEMPLATE/; # needed here to separate demo data my ($key, $val) = split; $values{$key} = $val; } # Pretend we have an input file w/template my $template = join '', <DATA>; # Process the fields for my $key (keys %values) { $template =~ s/%$key%/$values{$key}/g; } # Show result print $template; __DATA__ name Roadrunner job running TEMPLATE Hello Mr. %name%. We hope you are good at %job%.
For a more elegant approach to the substitution, replace entire process fields "for" loop with this: $template =~ s/%(\w+)%/$values{$1}/g;
If you are going to get serious about this, I suggest you look into one of the template modules.
------------------------------------------------------------
"Perl is a mess
and that's good because the
problem space is also a mess." - Larry Wall
|
|---|