CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: query a file, search another and output a third: Edit Log



dsaliba
Novice

May 29, 2013, 2:50 AM


Views: 447
query a file, search another and output a third

file1.txt
1
3
5

file2.txt
1 12378
2 98979
3 57778
4 87897
5 78979
6 29787

file3.txt
1 12378
5 78979

My issue is that I'm not getting all the outputs. Cannot understand what could be the issue. Would someone kindly point out why? Thank you.


Code
#! /usr/bin/perl 

open my $result,'>','file3.txt' or die $!;
open my $imsi,"<",'file2.txt' or die $!;
my %hash = map {split/\s+/,$_,2} <$imsi>;
open my $msisdn,'<','file1.txt' or die $!;
while($line=<$msisdn>){
chomp ($line);
if (exists $hash{$line}){
print $result "$line: $hash{$line}";
}
}



(This post was edited by dsaliba on May 29, 2013, 2:53 AM)


Edit Log:
Post edited by dsaliba (Novice) on May 29, 2013, 2:53 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives