Greetings, Here is one way to do it. Please note that I have retained your variable naming conventions and style instead of inventing my own.
[code] use strict; use warnings; my %complex_hash; my @ex = qw / 5326 2041 1391 1439 x1259 /; open my $fh, "<", "fullhost.txt" or die $!; while (<$fh>) { chomp; my $line = $_; my ($key, $value) = split /\s+/, $line; chomp $key; chomp $value; $complex_hash{$key} = $value; } for my $element (@ex) { foreach my $key (keys %complex_hash) { if($key =~ /$element/) { print " $element : \t\t\t ", $complex_hash{$key}, "\n"; } } } [/code] [output] 5326 : xng 2041 : VG 1391 : GYX 1439 : IDT x1259 : IDT [/output] Hope it helps. best, Shaji ------------------------------------------------------------------------------- Your talent is God's gift to you. What you do with it is your gift back to God. ------------------------------------------------------------------------------- On Friday, 13 December 2013 5:37 PM, jet speed <speedj...@googlemail.com> wrote: Dear All, I have sample code below, i am trying print the matching array element values sorted in the hash. As you would notice only one of the array element "x1259" will print its value "IDT" stored in the hash. Please could you advice how can i get rest of the array elements matched in the hash example "1439" in array element needs to print its value as "IDT", currently its not printing becase the key sorted in hash is "187333591439" . is there a way to do a search the key for the matching array element and print its value ? Ideally i would like get all the array element matched in the hash and print its value. Your inputs are much apprecaited to resolve this. Thanks --------------------------- fullhost.txt 187333591439 IDT e61391 GYX 2041-CX-1 VG 3333494 IDT e55326 xng x1259 IDT -------------------------- my %complex_hash; my @ex = qw / 5326 2041 1391 1439 x1259 /; open my $fh, "<", "fullhost.txt" or die $!; while (<$fh>) { Chomp; my $line = $_; my ($key, $value) split/\t+/,$line; $complex_hash{key} = $value; } for my $element (@ex) { print " $element \t\t\t $complex_hash{$element} \n" } ----------------------------------------------------------------------------- -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/