kmsripada has asked for the wisdom of the Perl Monks concerning the following question:

executing a perl program which creates report files and files are zipped. report file format can be csv or text. zipped files moved via ftp in binary mode to web server which is in windows 2000 environment.... when the file is extracted and opened in notepad in windows, end of line there are carriage return symbols...... to overcome this i have written a sub() to call unix2dos command on each file after creation and then zip them..... the files are now good........ as the files are huge in size at times and number of files processed are also more......is there any other better way than this, to improve performance........ using perl - 5.8.7, solaris unix, for zipping files using archive::zip module.............thanks....krishna

Replies are listed 'Best First'.
Re: unix2dos command
by ysth (Canon) on Jan 19, 2006 at 12:19 UTC
    When you create your report files, open them with the :crlf layer:
    open my $report_fh, ">:crlf", "report.csv" or die "Couldn't open rep +ort.csv: $!";
    or use binmode FH, ":crlf"; on the filehandle before you write to it.
      hi thanks to all of you for your suggestions
      martin.. i will remember to post with code next time
      thanks for your suggestion ysth
      open file in :crlf mode works.. i need not run unix2dos command on files where this perl program is creating
      for other files which this program pull from other sources ... i am still using unix2dos command before zipping and then moving to windows environment
      thanks
      krishna
Re: unix2dos command
by marto (Cardinal) on Jan 19, 2006 at 11:19 UTC
    kmsripada

    If you are asking how to improve performance it would be better if you posted the code you are using, that way people can give see exactly how you are achieving this and point out any improvements that could be made.

    I notice this is your first post (under this username), if you have not done so already please have a read at the PerlMonks FAQ and How do I post a question effectively?.

    Hope this helps.

    Martin
Re: unix2dos command
by blazar (Canon) on Jan 19, 2006 at 11:31 UTC

    <incidentally>
    For unix to dos (not the other way round!) I use

    perl -lpi.bak -e "" file.txt
    </incidentally>

    (Info-)ZIP's unzip supports -a (and -aa) cli params for line endings conversion. So maybe Archive::Zip supports something similar, although I must admit that a quick look at its documentation didn't reveal anything particularly relevant. Maybe there's still the possibility, but not that evident. OTOH you didn't say how you extract the files themselves: if with Info-ZIP, then just use those cli params and don't bother.

    Or else, depending on how you actually write the files, you may be interested in the ":crlf" output layer: see PerlIO.

Re: unix2dos command
by glasswalk3r (Friar) on Jan 19, 2006 at 11:59 UTC

    In the UNIX side, when you're processing the files, you just have to do something like this:

    while (<INPUT>) { #removes the UNIX style newline chomp; #do something else and then print to the OUTPUT file #using DOS style new line print OUTPUT, $line_content, "\r\n"; }

    Here is something to help improve the performance of your program: http://www-128.ibm.com/developerworks/library-combined/l-optperl.html.

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill