http://qs321.pair.com?node_id=984802

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

Wanting to use this module rather than IO::Compress. For some reason IO::Compress makes my text documents display all on one line in notepad opens fine in wordpad but would like the files to open perfectly in notepad.


#!perl use Modern::Perl; #use IO::Compress::Zip qw(zip $ZipError) ; use Archive::Zip; use IO::File my %files; my @files = <*.txt *.docx>; for (@files) { next unless /^(\d+.\d+.\d+.\d+)/; push @{ $files{$1} }, $_; } for my $ip ( keys %files ) { my $zip = Archive::Zip->new(); my $file_member = $zip->addFile($files{$ip} => "${ip}.zip"); my $fh_zip = IO::File->new( "${file}.zip", 'w' ); $fh_zip->binmode; unless ( $zip->writeToFileHandle($fh_zip) == 0 ) { $fh_zip->flush; $fh_zip->close; } $fh_zip->close; #zip $files{$ip} => "${ip}.zip" or die "zip failed: $ZipError\n"; }

Replies are listed 'Best First'.
Re: help with Archive::Zip
by suaveant (Parson) on Aug 01, 2012 at 14:57 UTC
    Well, all in one line in notepad but looks good in wordpad is a sure sign of unix style \n newlines instead of \r\n. You'll probably have to add something to convert to windows text, not sure if the module can handle that for you or if you have to do it manually (or find a module to handle it)

                    - Ant
                    - Some of my best work - (1 2 3)

      You have helped me pinpoint the problem my other problem is when I am reading in content and then try to print. I think im replicating the problem correctly. You helped clear up when i print to output directly rather than off of reading in a file or content from a webpage the problem is solved if i do \r\n when printing the output


      #!perl use File::Slurp; use strict; use warnings; my $textfile = 'inputfile.txt'; my $output_file = 'file.txt'; my $text = read_file($textfile); open(my $output_fh, '>',"$output_file") or die "Failed to open $output_file: $!"; print {$output_fh} $text, "\r\n"; close $output_fh;
        Yeah, web browsers handle the translation flawlessly, notepad is not quite so civilized. Glad I could help.

                        - Ant
                        - Some of my best work - (1 2 3)