Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Fuzzy matching of text strings

by Moron (Curate)
on Dec 15, 2005 at 15:20 UTC ( [id://516975]=note: print w/replies, xml ) Need Help??


in reply to Fuzzy matching of text strings

(untested) (updated to add more transformations)
#!/usr/bin/perl # usage: $0 [-d "delimiter"] file use strict; use warnings; my $delimiter = '\t'; if ( $ARGV[0] =~ /^\-(.)$/ ) { $_ = $ARGV[1]; if ( /^\"(.*)\"$/ ) { $delimiter = $1; shift @ARGV; shift @ARGV; } } my $file = join( '', @ARGV ); my %seen = (); open my $fh, "<$file" or die "$!: $file\n"; while( <$fh> ) { chomp; my @cols = split( /$delimiter/ ); for ( my $col=0; $col <= $#cols; $col++ ) { Check ( \%seen, $col[$col], $., $col+1 ); } } close $fh; sub Check { my ( $sref, $col, $lno, $colno ) = @_; my $lc = Transform( $col ); my $xref; if ( $xref = $sref -> { $lc } ) { ( $sref -> { $lc }{ $col } ) or print "Column $colno, Line $lno: ($col) " . "varies from " . ( values %$xref ); } else { $sref -> { $lc }{ $col } = "Column $colno, Line $lno: ($col)\n +"; } } sub Transform{ my $lc = lc( shift()); # example of an additional transformation... $lc =~ s/\s*//g; return $lc; }

-M

Free your mind

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-24 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found