in reply to Re: Re: Re: Re: Re: File write
in thread File write
Cheers.use Tie::IxHash; open DF, 'd.txt' or die $!; my %tagdict; while (<DF>) { chomp; my ($word, $cat) = split; $tagdict{$word} = $cat; } while ( ($k,$v) = each %tagdict ) { #print "$k => $v\n"; } close DF; open CF, 'c.txt' or die $!; my %tagcorpus; tie %tagcorpus,"Tie::IxHash"; while (<CF>) { chomp; my @cwords = split; @tagcorpus{@cwords} = (1) x @cwords; } while ( ($k,$v) = each %tagcorpus ) { #print "$k => $v\n"; } close CF; open CF, '+<c.txt' or die $!; seek CF, 0, 0; # go to start of file truncate CF, 0; foreach $citem(keys %tagcorpus){ #print "\n$citem"; print CF $citem; print CF " "; foreach $ditem(keys %tagdict){ my $currentposition=tell CF; seek CF,0,1 ; if ($citem eq $ditem){ print CF "$tagdict{$ditem}"; } } } close CF;
|
|---|