hi
i am using perl on windows ( active state perl 5.8 ) and i want to check for Control-M (^M) in file. files to be checked are in unix format so new line character is (\n). This perl script is called from Batch file ( windows .BAT file )
my script is
while (<PROGRAM>) {
chomp $_ ;
if ( /^M/ ) { # ^M - control-v + control-M
$useError = $1 ;
$checkFail++ ;
printf STDOUT "LineNo %6d : [$_] - \'Cntl+M\' used.\n", $. ;
}
}
close PROGRAM ;
this script is not working because when i do chomp perl removes ^M ( as its a new line character in windows ) so how can i check for ^M on windows perl ? ( it works if ^M is in between line )
reason i am doing this on windows is that this BATCH file is executed when somebody check in file into PVCS ( which is on windows server ) as all files are for unix servers they should not have ^M and i cant use SFU perl if i do that then i have to make sure that everyone using PVCS should have SFU installed on their system. so you must be wondering who puts ^M in this case some times people opens the file in notepad and then saves the file.
i dont want to remove ^M what i want is when user runs this script with 1 input parameter as file to be checked for ^M it should tell if file hash ^M or not ..
like
$ ./check.pl test.lst
LineNo 42 : [ xxxxxxxxxxxxxxxxx xxxxxxx ^M] - 'Cntl+M' used.
1 Lines needs to be changed.
and i can not use Unix commands here not even sed,awk i only have perl ( windows version ) installed. this script is wrapped in windows BATCH file.
i am putting ^M to test my code but it doesnt work on windows i can check for presence of ^M in file on unix but when i transfer the same file on windows with the same perl code ( but perl here is windows version of perl ) it doesnt work .
i have tried following ways to filnd ^M ...( all works on unix but not on windows )
if ($_ =~ /\cM/) ;
if ($_ =~ /\015/) ;
if ($_ =~ /\x0D/) ;
if ( $_ =~ /^M/ ) ;
lets see if its possible by any other way .... i will post the answer it if i am able to solve this