For this purpose, I've always just stored the ad-hoc value relationships as key/value pairs in a hash, and then returned the value for the key:
#!/usr/bin/perl use strict; my $TRUE = 1; my $FALSE = 0; my $KEY_ADHQRY = 'ADHQRY'; # Hash key for the ad hoc Quer +y my $KEY_ADHVAL = 'ADHVAL'; # Hash key for the ad hoc Valu +e my %Adhinf = (); # Ad hoc information # Get the ad hoc query/response values and populate the hash { print "Enter ad hoc values list in the following format: query->v +alue|query->value|query->value\n"; my $reqahv = <STDIN>; chomp $reqahv; my @adhelt = split /\|/, $reqahv; foreach my $adhelt (@adhelt) { my $wrkelt = $adhelt; $wrkelt =~ s/^\s+//; $wrkelt =~ s/\s+$//; my ($adhqry, $adhval) = split /\s*\-\>\s*/, $wrkelt, 2; my $adhkey = uc $adhqry; $Adhinf{$adhkey}{$KEY_ADHQRY} = $adhqry; $Adhinf{$adhkey}{$KEY_ADHVAL} = $adhval; } } # Test the query/response behavior { my $prcflg = $TRUE; while ($prcflg) { print " Enter query: "; my $reqqry = <STDIN>; chomp $reqqry; if ($reqqry =~ /^\s*$/) { $prcflg = $FALSE; last; } else { my $reqrsp = getAdHocResponse($reqqry); print " Response: $reqrsp\n"; print "\n"; } } } exit; sub getAdHocResponse { my ($reqqry, @arglst) = @_; if (!defined $reqqry) { $reqqry = ''; } my $retval = '{No Response}'; my $reqkey = uc $reqqry; if (defined $Adhinf{$reqkey}) { $retval = $Adhinf{$reqkey}{$KEY_ADHVAL}; } return $retval; }
And the test results:
C:\Steve\Dev\PerlMonks\P-2015-03-30@1459-Ad-Hoc-Conditionals>adhoc1.pl Enter ad hoc values list in the following format: query->value|query- +>value|query->value Steve->Pinger|Tom->Tony|Ronald->Kevin Enter query: mike Resposne: {No Response} Enter query: george Resposne: {No Response} Enter query: steve Resposne: Pinger Enter query: om Resposne: {No Response} Enter query: tom Resposne: Tony Enter query: kevin Resposne: {No Response} Enter query: ronald Resposne: Kevin Enter query:
In reply to Re: Module for Conditional Parsing
by marinersk
in thread Module for Conditional Parsing
by mwb613
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |