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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.