| [reply] |
Taking toolic's suggestion, I did this, stealing fairly directly from the Synopsis, and as seen below, to good effect.
Three points of note:
- When using the text file technique, the lines appear to come back either pre-chopped or pre-chomped;
- The internal line-counter feature is 1-based, not zero-based, and;
- 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>
| [reply] [d/l] [select] |
i actually made some progress on my own, but still not there yet
use warnings;
use Archive::Zip;
my $zip = Archive::Zip->new('test.zip');
# my $fh = $zip->memberNamed( { $zip => 'test1.txt'} );
my @members = $zip->memberNames();
# foreach my $member (@members) {
# print $member."\n";
# }
open OUT,">kiop_data.txt" or die "Cant open kiop_data.txt : $! \n ";
open my $file,"<$fh" or die "cant open \'$fh\' : $! \n";
my $lines = @$file[196609];
# print $Lines[196609]."\n";
close IN;
close OUT;
now i know it sees the files within the zip i just need to open that particular file up and load every line in an array. | [reply] [d/l] |
#!/usr/bin/perl
use strict ;
use warnings ;
use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
my $input = 'test.zip';
my $output ;
unzip $input => \$output, Name => "test1.txt" or die "unzip failed: $U
+nzipError\n";
my @lines = split("\n",$output);
print $lines[196609];
| [reply] [d/l] |