SPUG: Perl logic module?

Stuart Poulin stuart_poulin at yahoo.com
Wed Mar 24 18:45:23 CST 2004


Don't forget too that perl has a built in parser - you can sub in strings then eval the string.
i.e.
my $str = "-foo bar -a ( -bar stool -o -bar tab )";
$str =~ s/\s-a\s/ and /g;
$str =~ s/\s-o\s/ or /g;
$str =~ s/-foo\s+(\w+)/foo('$1')/g;
$str =~ s/-bar\s+(\w+)/bar('$1')/g;
print "$str\n";
my $results = eval $str;
print "Results = $results\n";
sub foo {
 my $arg = shift;
 return 1 if $arg eq 'bar';
 return 0;
}
sub bar {
 my $arg = shift;
 return 1 if ( $arg eq 'stool' or $arg eq 'drink' );
 return 0;
}



Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/spug-list/attachments/20040324/f1a51c0c/attachment.htm


More information about the spug-list mailing list