Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Reading from/writing to files with variables substitutions

by BillKSmith (Priest)
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025976]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2017-05-27 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?