I tweaked your answer format a little to simplify things. See comment below.

#! perl -sw use strict; local $\=$/; #! Added leading and removed trailing /'s for consistancy my %answers = ( '/WRB1/JJ1/VBZ1/NP1/IN1/NP2' => '/NP1/VBZ1(so)/JJ1 : /NP1/IN1/N +P2/VBZ1(really)/JJ1', '/WP/NP1/VB1/VBN1/PP1' => '/PP1/PP2/NP1(are)/VB1', ); my $question = 'How/WRB1 hot/JJ1 is/VBZ1 the core/NP1 of/IN1 the earth +/NP2 ?/'; my @keys = $question =~ m!(/[A-Z0-9]+)!g; # Parse markers # Update: Fixed problem not capturing all words between tags #my @values = $question =~ m!(\w+)(?=/)!g; # Parse values my @values = $question =~ m!(.*?)(?:/[A-Z0-9]+\s+)!g; my %lookup; @lookup{@keys} = @values; # Build lookup my $key = join'',@keys; my $answer = $answers{$key}; $answer =~ s!\s*$_\s*! $lookup{$_} !g for keys %lookup; $answer =~ s!\s+:\s+! and the !g; #$answer = 'The' . $answer; # Update: No longer needed. print $answer;

Output: (revised after changes)

C:\test>210085 the core is (so) hot and the core of the earth is (really) hot C:\test>

Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy

In reply to Re: Match key and return value in some order by BrowserUk
in thread Match key and return value in some order by Anonymous Monk

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.