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 ( #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? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2022-01-29 14:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (74 votes). Check out past polls.

    Notices?