in reply to Re^3: Strange character beginning text files
in thread Strange character beginning text files

Also for your interest your assertion that $/ is CRLF on Win32 is wrong, nor does chomp remove the \r. As I understand it there is some internal magic the means that non binmode file read/writes get converted but you can see that $/ is "\n" - at least on my system. I have been bitten by \r not getting eaten by chomp on multiple occasions, usually related to Win32->*nix issues.

C:\>type test.pl printf "CR \\r \\%03o 0x%02x\n", ord("\r"), ord("\r"); printf "LF \\n \\%03o 0x%02x\n", ord("\n"), ord("\n"); print $^O, $/; print "\$/ length ", length $/, " is ", (unpack "H*", $/), "\n\n"; my $str = "str\015\012"; for( 1..2 ) { print "string '$str'\n"; print "length ", length $str, "\n"; chomp $str; print "string '$str'\n"; print "length ", length $str, "\n\n"; } C:\>test.pl CR \r \015 0x0d LF \n \012 0x0a MSWin32 $/ length 1 is 0a string 'str ' length 5 'tring 'str length 4 'tring 'str length 4 'tring 'str length 4 C:\>

cheers

tachyon

Replies are listed 'Best First'.
Re^5: Strange character beginning text files
by wfsp (Abbot) on Jul 20, 2004 at 07:28 UTC
    ...bitten...

    Me too. When stripping text from an ms Word file chomp ignores \r. I have a 'trim' function for leading and trailing white space and I 'chomp' it there.

    There were also em dashes, elipsis, opening and closing single and double quotes and all the rest. As the text was being prepared for a web page HTML::Entities came to the rescue!