You're so close to getting this. The main problems with your code are my $one_number = $numbers[${$href{$name}} - 1]; and print "$name\t\t${$href{$name}}\t$one_number\n"; You're having some trouble with derefencing the arrays (and also with choosing the "one number"). The correct syntax would be $numbers[$href{$name}->[0]] (assuming you want the first element), or $numbers[${$href{$name}}[0]].

After seeing your updates, I think I'm a bit confused about exactly what you're trying to accomplish now. I had initially thought that you wanted to match each value in the array against every line in File2. If that is still the case, you need to add a nested loop.

Anyway, here is some updated code. I hope this does what you need it to do.

#!/usr/bin/perl -w use strict; use warnings; my %href; open my $fh, "<", "File1.txt" or die "Cannot open File1: $!"; while (<$fh>) { chomp; push @{$href{$1}}, $2 if /(\S+)\s+(\S+)/; } while (my ($key, $value) = each(%href)) { print "$key, (@{$value})\n"; } close $fh; open $fh, "<", "File2.txt" or die "Cannot open File2: $!"; { local $/ = '>'; while ( <$fh> ) { chomp; next unless ( s{ \A (\S+) \s+ (?= \d ) }{}xms and exists( $hre +f{$1} )); my $name = $1; my @numbers = split /\D+/; for my $index (@{$href{$name}}) { next if $index > $#numbers; if ($numbers[$index] >= 20) { print "$name\t\t$index\t$numbers[$index]\n"; } } } }

In reply to Re^3: Hash Key Limitation problem by lostjimmy
in thread Hash Key Limitation problem by ashnator

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.