#!/usr/bin/perl use strict; my $TRUE = 1; my $FALSE = 0; my $KEY_ADHQRY = 'ADHQRY'; # Hash key for the ad hoc Query my $KEY_ADHVAL = 'ADHVAL'; # Hash key for the ad hoc Value 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->value|query->value|query->value\n"; my $reqahv = ; 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 = ; 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; }