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

Hi To give a brief idea what i am doing here is parsing an HTML page and directing the output to a file, but the problem is i get end line character ^M after each line
The file looks like this
3072^M
3066^M
3040^M
3033^M
3032^M
#Print Numbers to a file print "File name: "; my $cr_f = <STDIN> ; open (STDOUT, ">$cr_f"); # Start parsing the following HTML file $p->parse_file("outpage.html"); my $get_next_text = 0; sub start{ # Execute when start tag is encountered my ($tagname,$attr) = @_; if ($tagname eq 'td' && exists $attr->{align} && $attr->{align} eq + 'right') { $get_next_text = 1; } else { $get_next_text = 0; } } sub text { { my $text = shift; print $text if $get_next_text; } } unlink ("outpage.html");

20040722 Edit by castaway: Changed title from 'STDOUT'

Replies are listed 'Best First'.
Re: Avoiding printing ^M to Avoiding printing ^M to STDOUT
by pbeckingham (Parson) on Jul 21, 2004 at 15:44 UTC

    What's the problem? If you want the character removed, then remove it.

    Are those nested braces intentional in sub text {{ ... }}?

Re: Avoiding printing ^M to STDOUT
by sgifford (Prior) on Jul 21, 2004 at 19:37 UTC

    If those ^M's are in the source file and you're copying them from there, you'll want to use a regex to remove them; the one suggested by xorl should work fine.

    If you're running on an OS like Windows that likes to put CR/LF at the end of its lines, you'll want to use binmode to tell Perl not to do that.

Re: Avoiding printing ^M to STDOUT
by xorl (Deacon) on Jul 21, 2004 at 15:45 UTC
    Use this regex on the file: s/\r\n$/\n/g I haven't tested it but I think it should work.