in reply to Re^11: compare two text file line by line, how to optimise
in thread compare two text file line by line, how to optimise

hi i don't understand this part of code

 my @match = grep $uniq1{$_}, @words; what i understand : here we search for $uniq1{$_} in @words

we know that @words contain the current line, but $uniq1{$_} what does it contain? and if $uniq1{$_} contain the line of the file N°1 how to browse(iterate) it and how to change from a value to another

Replies are listed 'Best First'.
Re^13: compare two text file line by line, how to optimise
by poj (Abbot) on Mar 01, 2016 at 08:23 UTC
    while (<FICC>) { my @words = split /\s+/,lc $_; ++$uniq1{$_} for @words; }

    $uniq1{$_} contains all the words from file1 like a dictionary. $uniq1{'anyword'} will be undef or 0 if 'anyword' was not in file1.
    Try a simple example

    #!perl my %uniq1= ( cow => 1, dog => 1, fox => 1, ); my @words = ('ant','bat','cat','dog','eel','fox'); my @match = grep $uniq1{$_}, @words; print "@match\n"
    poj

      Now i understand

      But my probelm is to compare line by line, and not only find the word in the $uniq1,so i search by combination, may be i must use a hash of array to stock the word of each line