Using Perl Win7 to write a file for Linux and having only Linux line endings -


this perl script running on win7, modifying clearcase config spec read on linux machine. clearcase fussy line endings, must precisely , \n (0x0a) try may cannot perl spit out \n endings, come out \r\n (0x0d 0x0a)

here's perl snippet, running on array of config spec elements , converting element /somevob/... bits element /vobs/somevob/... , printing file handle.

        $fh = new filehandle;     foreach $line (@cs_array)         {         $line =~ s/([element|load])(\s+\/)(.+)/$1$2vobs\/$3/g;          $line =~ s/[\r\n]/\n/g;  # tried many things here         $fh->print($line);         }     $fh->close(); 

sometimes elements in array multi-line , separated \n

element /vob1/path\nelement\n/vob2/path\nload /vob1/path\n element\n /vob3/path  load /vob3/path 

when file written on win7 in binary viewer there 0x0d 0x0a newline sequence clearcase on linux complains about. appears come print.

any suggestions? thought 10 minute job...

try

$fh->binmode; 

otherwise you're in text mode, , windows means \n translated \r\n.


Comments