This way you can use whatever perl translations that you want. Also, it would be up to you what you pass to the subroutines and if it needed to return anything.#!/usr/bin/perl -w use strict; use warnings; # Build list of translation rules my @rules; while (<DATA>) { chomp; my ($pattern, $code) = split "\t"; push @rules, [$pattern, eval "sub {$code}"]; warn $@ if $@; }; # Fake Data my @lines = ( "this is foo\n", "this is bar\n", "this is baz and foo\n", ); # Process the lines using compiled rules. for my $line (@lines) { for my $rule (@rules) { if ($line =~ /$rule->[0]/) { $rule->[1]->($line); } } print "$line"; } __DATA__ foo $_[0] =~ s/foo/FOO/; bar $_[0] =~ s/bar/BAR/; baz $_[0] =~ s/baz/BAZ/;
In reply to Re: Converting strings read from a file into perl commands
by wind
in thread Converting strings read from a file into perl commands
by Nightthrall
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |