Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Reading from/writing to files with variables substitutions

by BillKSmith (Chaplain)
on Mar 28, 2013 at 15:24 UTC ( #1025976=note: print w/ replies, xml ) Need Help??


in reply to Reading from/writing to files with variables substitutions

Use a hash and a regex with the /e option.

#!perl -p use strict; use warnings; #Usage: perl script.pl boiler.txt >outfile.txt BEGIN{ use vars qw( %hash $pattern ); %hash = ( FIRST_NAME => 'James', COMPANY => 'SoftLayer', ); $pattern = join '|', keys %hash; } s/\$($pattern)/$hash{$1}/ge;
Bill


Comment on Re: Reading from/writing to files with variables substitutions
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2014-09-02 20:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (29 votes), past polls