b_vulnerability has asked for the wisdom of the Perl Monks concerning the following question:
which is the result of a POS tagging.L'/lo/RDNS harmonium/harmonium/S Ë/essere/V-S3IP uno/uno/RIMS stru +mento/strumento/S-MS musicale/musicale/A-NS azionato/azionare/V-MSP +R con/con/E una/una/RIFS tastiera/tastiera/S-FS
I need to do something that takes both file as input and print me everything that's between the first "word" which is really a string and the second one.[Nn]ucle[oi]/nucleo/S-MS:[Pp]roton[oi]/protone/S-MP [Aa]tom[oi]/atomo/S-MS:[Nn]ucle[oi]/nucleo/S-MS
but obviously the regex ($text =~ / $key (.*)? $value /g) isn't too accurate. I would like for it to match just string that have the first "word" than 3 or 4 other "words" and than the second one. Is it possible? How should I do it? Is the rest of the code any good? Thanks for your help.#!/usr/bin/perl use strict; use warnings; open my $listaParole,"<File_with_the_words" or die; my %hash; while (my $line=<$listaParole>) { chomp $line; my ($word1, $word2) = split /:/, $line; $hash{$word1} = $word2; } while ( my ($k,$v) = each %hash ) { print "Key $k => $v\n"; } open my $testo, "<File_with_the_text"; open my $lista_relazioni, ">Output"; my @arrayris =() ; my $indice=0; while (my $text=<$testo>){ for my $key (keys %hash){ my $value = $hash{$key}; while ($text =~ / $key (.*)? $value /g) { $arrayris[$indice]=$1; $indice++; } } } my $indice_controllo=1; foreach (@arrayris) { print $lista_relazioni "($indice_controllo) $_\n"; $indice_controllo++; } close $testo; close $lista_relazioni;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex matching
by missingthepoint (Friar) on Nov 04, 2008 at 01:16 UTC | |
by b_vulnerability (Novice) on Nov 04, 2008 at 08:49 UTC | |
by Cristoforo (Curate) on Nov 04, 2008 at 21:08 UTC | |
|
Re: Regex matching
by JavaFan (Canon) on Nov 03, 2008 at 16:29 UTC | |
by b_vulnerability (Novice) on Nov 03, 2008 at 16:47 UTC |