Taking toolic's suggestion, I did this, stealing fairly directly from the Synopsis, and as seen below, to good effect.

Three points of note:

  1. When using the text file technique, the lines appear to come back either pre-chopped or pre-chomped;
  2. The internal line-counter feature is 1-based, not zero-based, and;
  3. As written, it may have added an extra line to the end of the file. I have examined neither the accuracy of this supposition, nor its cause (if real). That is left as an exercise for the reader. If it is real, that might be due to the way the while()loop is constructed for reading the file.

#!/usr/bin/perl use strict; use Archive::Zip; use Archive::Zip::MemberRead; my ($zipfnm, $mbrfnm, @arglst) = @ARGV; { if (-e $zipfnm) { # ZIP file exists. Proceed. my $zipobj = Archive::Zip->new($zipfnm); # ZIP obje +ct pointer # Adjust Windows specifications my $mbranm = $mbrfnm; $mbranm =~ s/\\/\//g; # Proceed. my $mbrhan = Archive::Zip::MemberRead->new($zipobj, $mbranm) +; # Synopsis does not specify error handling return; # Left as an exercise for the reader :-) # OP indicates reading lines from the file, so use the text +file technique while (defined(my $inpbuf = $mbrhan->getline())) { # Note the line read is already chopped or chomped (!!) print "Line " . $mbrhan->input_line_number . ": [$inpbu +f]\n"; } } } exit; __END__

Results:

D:\PerlMonks>"C:\App\7-Zip\7z.exe" l -tzip test.zip 7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18 Listing archive: test.zip -- Path = test.zip Type = zip Physical Size = 17540 Date Time Attr Size Compressed Name ------------------- ----- ------------ ------------ ----------------- +------- 1995-03-03 22:42:08 ....A 24361 16886 binary.dat 2015-03-10 15:40:58 ....A 22 22 test.dat 2015-03-10 15:41:09 ....A 28 28 test2.dat 2015-04-23 19:41:25 ....A 82 62 test3.txt ------------------- ----- ------------ ------------ ----------------- +------- 24493 16998 4 files, 0 folder +s D:\PerlMonks>type test3.txt This is line one. This is line two. This is line four. The third was blank. D:\PerlMonks>zipreadfile1.pl test.zip test3.txt Line 1: [This is line one.] Line 2: [This is line two.] Line 3: [] Line 4: [This is line four. The third was blank.] Line 4: [] D:\PerlMonks>


In reply to Re^2: Need to parse a file within a zip file by marinersk
in thread Need to parse a file within a zip fille by gotsilk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.