in reply to Returning Variables from files

Here's another possibility: its not as powerful as the eval method; but much safer:
my %values = (title => "A Title"); sub get_value { my $key = shift; return exists($values{$key}) ? $values{$key} : "UNKNOWN"; } my $file = "User.htm"; open IN, "<$file" or die "can't read file: $file"; while (<IN>) { s/\$(\w+)/get_value($1)/ge; print; }
You can obviously get a bit more fancy with the get_value subroutine --Dave.

Replies are listed 'Best First'.
Re: Re: Returning Variables from files
by Anonymous Monk on Jul 21, 2002 at 22:10 UTC
    what if I wanted to do subroutines