Buying $10 for super easy 5 minute Perl program...

Discussion in 'Programming' started by BandonFlyer, Apr 13, 2010.

  1. #1
    I have a text file that is formatted oddly...

    I'm running in Windows environment and need an extremely simple 4 or 5 lines of Perl to fix this. The solution must be Perl and must run on Windows as it will integrated into a much larger Perl script.

    The file at the end of the first line terminates with 0d 0d 0a 0d 0d 0a or LF (linefeed) LF CR (carriage return) LF LF CR

    This structure causes me problems. I want the LF LF CR to be replaced with a standard Windows CR LF...

    I have tried simple s/\n//g type stuff and i can't get it to work. Have also tried opening the file in binary mode - again - no luck...

    Send me a PM if you can do this - you must be able to do it IMMEDIATELY - this is not a get back to me later project...

    Send me your email address in the PM so I can email you the sample file. I will PayPal $10 immediately upon confirmation that the code works.

    Thanks
     
    BandonFlyer, Apr 13, 2010 IP
  2. Kaimi

    Kaimi Peon

    Messages:
    60
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    Try
    
    {
    	undef local $/;
    	open(F, '+<file.txt') || die $!;
    	my $str = <F>;
    	$str =~ s/\n\n\r/\r\n/g;
    	truncate F, length $str;
    	sysseek F, 0, 0;
    	syswrite F, $str;
    	close F;
    }
    
    Code (markup):
     
    Kaimi, Apr 14, 2010 IP