I primarily work in a linux server environment. I often encounter files that were originally written on another operating system. That can make life hard for scripts like the following:
I'd like my scripts to be platform-agnotic, that is, process files regardless of being created on a Unix, Windows or Mac platform.$ echo -e "123\n456\n789" > foo.txt $ hexdump -C foo.txt 00000000 31 32 33 0a 34 35 36 0a 37 38 39 0a |123.456.7 +89.| 0000000c $ cat foo.txt | perl -wle 'use strict; while(my $line = <>) { chomp $l +ine; ($line =~ m/^\d+$/) ? print qq{number ok:"$line"} : print qq{num +ber error:"$line"} }' number ok:"123" number ok:"456" number ok:"789" $ unix2dos foo.txt unix2dos: converting file foo.txt to DOS format ... $ hexdump -C foo.txt 00000000 31 32 33 0d 0a 34 35 36 0d 0a 37 38 39 0d 0a |123..456. +.789..| 0000000f $ cat foo.txt | perl -wle 'use strict; while(my $line = <>) { chomp $l +ine; ($line =~ m/^\d+$/) ? print qq{number ok:"$line"} : print qq{num +ber error:"$line"} }' "umber error:"123 "umber error:"456 "umber error:"789 $
I use unix2dos manually on occations, but I'd rather have my perl scripts do this themselves when they encounter files created on a foreign operating system. Is there a reliable way to do this?
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |