#!/usr/bin/perl -sw use Data::Dumper; use strict; local $\=$/; my %patterns; open(PFILE, "whatpattern.txt")|| die "Cannot open whatpattern.txt file +"; while (<PFILE>) { chomp; next unless $_; my @tags = split /; |:/; my $key = shift @tags; $patterns{$key} = \@tags; } open(TESTFILE, "alltestfile")|| die "Cannot open alltestfile"; while(defined(my $question=<TESTFILE>)) { my @qkeys = $question =~ m!(/[A-Z0-9]+)!g; my @qvalues = $question =~ m!(.*?)(?:/[A-Z0-9]+\s+)!g; my %questionlookup; @questionlookup{@qkeys} = @qvalues; my $key = join'',@qkeys; print $question."\n\n"; if (my $answer = $patterns{$key}) { $answer =~ s!\s*$_\s*! $questionlookup{$_} !g for qkeys %questionloo +kup; $answer =~ s/\:/\n\n/g; print $answer; } else{ print "No Match\n"; } }
In reply to Re: Re: Re: Re: Match key and return value in some order
by Anonymous Monk
in thread Match key and return value in some order
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |