Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Comparing strings from different files

by Lennotoecom (Pilgrim)
on Oct 08, 2013 at 20:48 UTC ( [id://1057461]=note: print w/replies, xml ) Need Help??


in reply to Comparing strings from different files

If you are comparing actual lines from the files
and not the different "nodes"
then your task is even easier
something like that:
./sciprt.pl FILE1 FILE2
%hash = map{ s/E99/99/g; $_ => $hash{$_}++;} <>; foreach (sort keys %hash){ print "$_ $hash{$_}\n" if !$hash{$_}; }
will print you yours unique lines

Replies are listed 'Best First'.
Re^2: Comparing strings from different files
by Jalcock501 (Sexton) on Oct 09, 2013 at 08:59 UTC
    Thanks for this it works great, however I need to run this on loads of files, I've had a play and can't seem to automate the command line arguments. Here's what I have but it doesn't work (probably because I'm not doing it right)
    #!/usr/bin/perl -w use strict; my @files = <*.in.sep>; my %hash; for(@files) { s/[.]in[.]sep//g } for my $file (@files) { open (my $in, "<", "$file.in.sep") || die ("cannot open $file"); open (my $out,"<", "$file.out.sep") || die ("cannot open search.tx +t"); %hash = map{ s/E99/99/g; $_ => $hash{$_}++;} <$in, $out>; foreach (sort keys %hash){ print "$_ $hash{$_}\n" if !$hash{$_}; } }
    Thanks Jim
      well I tested it on different files,
      but the main idea is:
      foreach (<*.in.sep>){ $name = $` if /.in.sep/; open IN, $_ or die $!; open OUT, $name.'.out.sep' or die $!; %hash = map{ s/E99/99/g; $_ => $hash{$_}++;} <IN>, <OU +T>; close IN, OUT; foreach (sort keys %hash){ print "$_ $hash{$_}\n" if !$hash{$_}; } }
      correct if there are mistakes,
      or if it might be optimized
      ty)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1057461]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-26 06:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found