Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How to delete the strings in the line when it finds the character "<" till the end of the line and until it finds the character '{'.
#!/usr/bin/perl while(<DATA>){ s/<(.*){//; } __DATA__ EVITE LA ENFERMEDAD PERIODONTAL< EVITE LA ENFERMEDAD PERIODONTAL< AS {IT}CTIQUE LA HIGIENE DENTAL PARA CUIDAR SUS ENCÃ

Replies are listed 'Best First'.
Re: Delete till end of line to another string
by rovf (Priest) on Aug 18, 2009 at 11:10 UTC

    The trick here is to use the non-eager version of * (code not tested):

    s/ < # match '<' .*? # match anything, but as short as possible (\{|$) # match either '{' or end of line //x
    BTW, this also removes the '{'.

    -- 
    Ronald Fischer <ynnor@mm.st>
      The format of the file contains Ascii characters. When I try to print the line,it only prints till EVITE LA ENFERMEDAD PERIODONTAL<. Please tell me any way we can encode the file
      #!/usr/bin/perl while(<DATA>){ $_ =~ s/<.*?(\{|$)//x; print $_; } __DATA__ EVITE LA ENFERMEDAD PERIODONTAL< AS {IT}CTIQUE LA HIGIENE DENTAL PARA CUIDAR SUS ENCà Cuando hace casi d +os años visité a mi dentista para hacerme un chequeo dental , me encontré ante un problema que podía terminar con mi dent +adura. Siempre tuve unos dientes sanos y jamás se me ocurrió pensar que pod +ía perder
        The format of the file contains Ascii characters.
        ??? I think you mean "contains non-ascii characters".
        it only prints till EVITE LA ENFERMEDAD PERIODONTAL<
        Are you sure that it also prints the '<' less sign? With the code you have posted, the '<' should not be printed. At least it does not for me:
        $ perl -lwe 'my $_="EVITE LA ENFERMEDAD PERIODONTAL< AS"; s/<.*?(\{ +|$)//; pr int' EVITE LA ENFERMEDAD PERIODONTAL
        Please tell me any way we can encode the file
        I'm not sure what you mean by "encode the file". Maybe you find what you need in perlio, where the encoding layer is described.

        -- 
        Ronald Fischer <ynnor@mm.st>
Re: Delete till end of line to another string
by bichonfrise74 (Vicar) on Aug 18, 2009 at 16:40 UTC
    Is this what you are looking for?
    #!/usr/bin/perl use strict; my $count = 0; while( <DATA> ) { $count = 1 if ( /\</ ); $count = 0 if ( /^{/ ); print if ( $count == 0 ); } __DATA__ hello EVITE LA ENFERMEDAD PERIODONTAL< EVITE LA ENFERMEDAD PERIODONTAL< AS {IT}CTIQUE LA HIGIENE DENTAL PARA CUIDAR SUS ENCÃ test test
Re: Delete till end of line to another string
by saranperl (Initiate) on Aug 19, 2009 at 06:12 UTC
    $_ =~ m/\{/g; $str = $`; $str1=$'; $str=~ s/\>//g; print $str."{".$str1;
    This will work !!!!

      Not really.

      If there is a line in the input data that has neither a > or a { it will produce a wrong result.

      use strict; use warnings; while (<DATA>) { $_ =~ m/\{/g; my $str = $`; my $str1=$'; $str=~ s/\>//g; print $str."{".$str1; } __DATA__ testline1 EVITE LA ENFERMEDAD PERIODONTAL< EVITE LA ENFERMEDAD PERIODONTAL< AS {IT}CTIQUE LA HIGIENE DENTAL PARA CUIDAR SUS ENCÃ testline2 testline3
      produces the output
      Use of uninitialized value in substitution (s///) at ... Use of uninitialized value in concatenation (.) or string at ... <snip other warnings> {{{{IT}CTIQUE LA HIGIENE DENTAL PARA CUIDAR SUS ENCÃ <snip more warnings> {IT}CTIQUE LA HIGIENE DENTAL PARA CUIDAR SUS ENCÃ <snip more warnings> {IT}CTIQUE LA HIGIENE DENTAL PARA CUIDAR SUS ENCÃ

      cheers, si_lence

      I apologize for the lack of exclamation marks in this post
Re: Delete till end of line to another string
by sanku (Beadle) on Aug 25, 2009 at 05:44 UTC
    hi try out this one... while($line=<DATA>){ $line=~s/<\s+\w+//g; $line=~s/<\s+//g; print $line; }
A reply falls below the community's threshold of quality. You may see it by logging in.