[lug] Re: Self-modifying Perl

Bill Thoen bthoen at gisnet.com
Wed Oct 4 15:52:11 MDT 2006


Never mind... I just discovered the 'eval' command and answered my own
question!

On Wed, Oct 04, 2006 at 03:39:51PM -0600, Bill Thoen wrote:
> Is there a way to execute Perl regex commands as variables within Perl? For
> eaxmple, this doesn't work, but is something like it possible?
> 
> #!/usr/bin/perl
> 
> my $cmd = 's/\d/!/g';
> while (<>) {
>   chop;
>   $cmd;
>   print "$_\n";
> }
> 
> What I'd like to be able to do is execute $cmd as if it were the substitute
> regex. Ultimately, $cmd would be "fed" from a data file, which would allow
> the program to behave differently depend on which data file I feed it.
> 
> - Bill Thoen
> 



More information about the LUG mailing list