What you should probably do is to use hashes. Something like this:
1. Read the first file. 2. Split the each item of first file using an hyphen 3. Store the first item as the keys of hash say - file1_hash 4. Read the second file and store the items as the keys of a new hash say - file2_hash 5. Loop through the file1_hash and determine the keys that are not present in - file2_hash ~Parag On Mon, Feb 14, 2011 at 4:09 PM, William Muriithi < william.murii...@epicadvertising.com> wrote: > Pal, > > I have to files that I am trying to match: > > Generated from rpm -qa > file1 > file1 > libstdc++-4.1.2-48.el5 > info-4.8-14.el5 > libICE-1.0.1-2.1 > libacl-2.2.39-6.el5 > lcms-1.18-0.1.beta1.el5_3.2 > dmidecode-2.10-3.el5 > ....... > > Generate from rpm -qa --queryformat '%{NAME}\n' > file2 > file2 > acl > alacarte > alchemist > alsa-lib > alsa-utils > amtu > apr > apr-util > aspell > aspell-en > .............. > > I am trying to list files that exist on file1 that are missing on file2 and > have the following script: > > #! /usr/bin/perl > > use strict; > #use warning; > > open MSRT, "/Users/williamm/Documents/file1" or die $!; > open Test_server, "/Users/williamm/Documents/file2" or die $1; > #open MSRT, "/Users/williamm/test1_rpm.txt" or die $1; > #open Test_server, "/Users/williamm/test2_rpm.txt" or die $1; > > my $tom; > my $msrt; > > while ($tom = <Test_server>) { > chomp($tom); > # print "T:$tom\n"; > while ($msrt = <MSRT>) { > chomp($msrt); > # print "M:$msrt\n"; > if ($msrt =~ /^\Q$tom\E/){ > # if ($msrt =~ m/^$tom.*$/){ > print "$tom: $msrt\n"; > # print "Found\n"; > } > } > } > > > williamcomputer:~ williamm$ perl compareRPM.pl > acl-2.2.39-6.el5: acl-2.2.39-6.el5 > > It does loop through the two files fine, but I think the regular expression > is not working fine. It only match one RPM, but I have been able to find > many others that should have matched. For example, this should have been > printed out. > > krb5-libs-1.6.1-36.el5_4.1: krb5-libs > > Any idea of what tweak to the regular expression I need apply to make it > work properly? Also, advice of a better way of solving this problem would > also be appreciated. > > Thanks in advance > > William > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >