in reply to Delete till end of line to another string

$_ =~ m/\{/g; $str = $`; $str1=$'; $str=~ s/\>//g; print $str."{".$str1;
This will work !!!!

Replies are listed 'Best First'.
Re^2: Delete till end of line to another string
by si_lence (Deacon) on Aug 19, 2009 at 07:06 UTC

    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