No doubt that chomp() is frequently used in all kinds of Perl scripts. Today, I spent a few seconds on a Perl script file which is to eliminate all the illegal chars of a XML files, expecting to get the work done soon. It wasn't, however. The code looked extremely plain and straightforward, but it simply refused to work. Soon I realized that I was working under Windows - literally the first time I wrote a Perl script under Windows! The problem was EOL, the End-Of-Line mark. While LF('\n') is sufficient to make a new line under *nix, Windows needs CR+LR("\r\n") to separate paragraphs. Here is what I use now:
while($line = <FILE>) {
$line =~ s/\r\n$//;
//do your work
}
Hope this helps.
Tuesday, June 16, 2009
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment