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

Hi,

I would like to do basically a chomp operation on each line of an rtf document. I was trying this, I think in rtf newline is \line :

$str =~ s//\line//g;

is said illegal division by zero (?)

Thanks

Replies are listed 'Best First'.
Re: rtf newline remove
by johngg (Canon) on Feb 20, 2010 at 00:11 UTC

    I know nothing about RTF files but perhaps you could localise the input record separator (see $INPUT_RECORD_SEPARATOR or $/ in perlvar).

    knoppix@Microknoppix:~$ perl -E ' > $text = q{Some txt\lineAnother line\lineLast line of text\line}; > say for do { > local $/ = q{\line}; > open $in, q{<}, \$text or die $!; > map { chomp; $_ } <$in>; > };' Some txt Another line Last line of text knoppix@Microknoppix:~$

    I hope this is helpful.

    Cheers,

    JohnGG

Re: rtf newline remove
by kennethk (Abbot) on Feb 19, 2010 at 23:50 UTC
    You've got too many slashes. The expression you want will likely look like:

    $str =~ s/line//g;

    where "line" should be replaced by whatever you are trying to eliminate. See perlre or perlretut for information on using regular expressions. We could give better guidance if you included some input and expected output - see How do I post a question effectively?.