Greetings DeusVult,
I'm not sure how security-wise this may be, but I think it's better than running an eval of user-changable data. Give this a try and let me know what you think. I've assumed a few things here, and I've also made @file_contents so you can see some dummy file data.
#!/usr/bin/perl -w use strict; my @file_contents; $file_contents[0] = 'My name is $name.'; $file_contents[1] = 'I live in the city of $city.'; $file_contents[2] = '$city is in the state of $state.'; my $file_contents = join("\n", @file_contents); my %stuff_to_parse = ( name => 'Gryphon', city => 'Seattle', state => 'Washington' ); foreach (keys %stuff_to_parse) { $file_contents =~ s/\$$_\b/$stuff_to_parse{$_}/g; } @file_contents = split(/\n/, $file_contents); foreach (@file_contents) { print $_, "\n"; }
Does this help? Also, anyone out there: Can someone tell me if I made any security mistakes here? Also, the \b on the end of the search pattern could be altered to be a little more robust.
-Gryphon.
In reply to Re: Digging interpolation deeper
by gryphon
in thread Digging interpolation deeper
by DeusVult
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |