Adriano Allora wrote:
> hi to all,

Hello,

> I've got a list of tagged words, like this one (only a little bit longest):
> 
> <tLn nr=11>
> e       CON     e
> le      DET:def il
> ha      VER:pres        avere|riavere
> detto   VER:pper        dire
> <       NOM     <unknown>
> CORR    VER:infi        corre
>>       NOM     <unknown>
> e       CON     e
> a       PRE     a
> 
> I need to transform the list below in (in which the CORR tag isn't tagged):
> 
> <tLn nr=11>
> e       CON     e
> le      DET:def il
> ha      VER:pres        avere|riavere
> detto   VER:pper        dire
> <CORR>
> e       CON     e
> a       PRE     a
> 
> So I tried to write this awful script:
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> $^I = '';
> 
> my $tic = 0;
> my  $toc = 0;
> 
> while(<>)
>     {
>     if(/^<       NOM     <unknown>.*/i)
>         {
>         $tic = 1;
>         next;
>         }
>     next if /^>       NOM     <unknown>.*/i;
>     next if $toc == 1;

Below you set $toc = 1 for the line you want modified so everything after the
line you want modified is bypassed.

>     $toc = 0;
>     if($tic==1)
>         {
>         s/^(\/?\w+).+/$1/gi;
>         chomp();
>         $_ = "<$_>";
>         $toc = 1;
>         $tic = 0;
>         }
>     s/<>//g;
>     print;
>     }
> 
> it doesn't return errors, but it stop printing the output after the
> first correction. Someone can explain me why and eventually suggest how
> to correct the corrector?

This should do what you want:

while ( <> ) {
    if ( /^<\s+NOM\s+<unknown>/i .. /^>\s+NOM\s+<unknown>/i ) {
        s!^(/?\w+).+!<$1>!g or next;
        }
    print;
    }


> PS: another strange thing: if I declare at the beginning of the script:
> my($tic,$toc); it returns me an error...

Probably because they are undefined and you are using them with a comparison
operator?



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to