in reply to Problem in counting the occurrences of a string in a text file
#!/usr/bin/perl use strict; use warnings; open( INPUT, "<Wiki_Pulito/Prova/Pattern2.txt") or die "Can't open Pat +tern2.txt"; open( LISTAPAROLE,"<File_Input/Coppie_Parole.txt") or die "Can't open +Coppie_Parole.txt"; my %hash; while (<INPUT>) { chomp; my ($word1, $word2) = split /:/, $_; $hash{$word1} = $word2; } close INPUT; # Carico la parte di file di testo che va analizzata open( CONTEGGIO, ">Wiki_Pulito/Prova/Conteggio.txt") or die "Can't ope +n Conteggio.txt"; # Apro il file di output my $conto=0; my %arrayris; while (my $text = <LISTAPAROLE>){ for my $key (keys %hash){ my $value = $hash{$key}; if ($text =~/$key\/$key\/.*con\/con\/E.*$value\/$value +\/S/is){ $conto++; } my $arrkey=$key."-".$value; $arrayris{$arrkey}=$conto; } } while ( my ($k,$v) = each %arrayris ) { print CONTEGGIO "($k) => $v\n"; } close LISTAPAROLE; close CONTEGGIO;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem in counting the occurrences of a string in a text file
by u671296 (Sexton) on Dec 29, 2008 at 16:42 UTC | |
|
Re^2: Problem in counting the occurrences of a string in a text file
by findtheriver (Initiate) on Dec 29, 2008 at 21:20 UTC | |
by linuxer (Curate) on Dec 29, 2008 at 21:31 UTC |