#!/usr/bin/perl # # Requirements: # 1) Provide a stand alone Perl program that eficiently stores lines occuring in # $shortfile, but not in $longfile, into $differences. # # dupslib.pm contains subroutines to provide input content and consume the output. # # by Chris Yager # (c) 2005 ############################################################ use strict; use warnings; use dupslib; ## library to fill scalers & output the $differences. my $shortfile; my $longfile; my $differences = ""; my %myhash = (); ($shortfile, $longfile) = fill_scalers(); # get input. # put $longfile into a hash. my @lines = split("\n", $longfile); # split into lines. foreach my $line (@lines) { # for each line in lines. $myhash{$line}=1; # use line as hash key. } # find lines of $shortfile in the hash. my @strs = split("\n", $shortfile); # split into lines. foreach my $str (@strs) { # for each line in lines. if (exists $myhash{$str}) # test existence of key. { } # do nothing (already exists). else {$differences = $differences."$str\n"}; # append to $differences. } # These 2 lines do the same as the 2 groups of lines above. # map $myhash{$_}=1, split(/\n/,$longfile); # make hash. # map {$differences.=exists $myhash{$_}?'':"$_\n"} split(/\n/,$shortfile); # find. save_results($differences); # do something with the results. exit;