in reply to Re^2: comparing columns and printing a result
in thread comparing columns and printing a result
TP, 9501, and E-SS.SUUTINKÄRKI SPRAY TP 9501 E-SS;SUUTIN VALME HOL0125624 TP 9501 E-S +S
#!/usr/bin/perl use strict; use warnings; my $readfile = 'blah.csv'; my $writefile = 'bleh.csv'; open my $fh, "<", $readfile or die "Unable to open $readfile: $!"; open my $wfh, ">", $writefile or die "Unable to open $writefile: $!"; foreach (<$fh>) { $_ = uc $_; chomp; my ($col1, $col2) = split /;/; my @col1_words = split /\s+/, $col1; my @col2_words = split /\s+/, $col2; my $found = 0; my $pattern = join ('|', @col1_words); for my $col2_word (@col2_words) { $found++ if $col2_word =~ /$pattern/; } print $wfh "$_;".@col1_words.";$found\n"; } close ($fh); close ($wfh);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: comparing columns and printing a result
by slartsa (Initiate) on Jan 26, 2009 at 14:42 UTC | |
by cdarke (Prior) on Jan 26, 2009 at 15:57 UTC | |
|
Re^4: comparing columns and printing a result
by slartsa (Initiate) on Jan 27, 2009 at 07:25 UTC |