简体   繁体   中英

Accessing a specific file in zipped folder using perl (perl module)

I am trying to access a text file within a zipped folder to extract a certain information, without actually unzipping the file. I am trying to use Archive::Zip. The directory structure is like Data_stats.zip--> Data_stats/ --> full_data_stats.txt. Now I tried this

use Archive::Zip;
use Archive::Zip::MemberRead;
use File::Basename;

$zip_dir=$ARGV[0];
@name =split("\\.",basename($zip_dir)); ## to get zipped folder name
$dir = Archive::Zip->new("$zip_dir");
$fh = Archive::Zip::MemberRead->new($dir,"$name[0]/full_data_stats.txt"); ##trying to reads the file giving the path and mentioning the specific file name

while (defined($line = $fh->getline()))
{
{print}
}

I see it extracting the folder but not reading in the file !!.

Regards

You are assigning to $line but printing $_; try print $line;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM