Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Returning Variables from files

by dpuu (Chaplain)
on Jul 21, 2002 at 21:03 UTC ( [id://183872]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://183872]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-23 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found