Search code examples
linuxperlunzip

Why i am getting IO::Uncompress::Unzip::unzip: input filename is undef or null string message?


I am having a folder with many zip files. I need to get any of these zip file, extract it and get a particular file from the ziped file. I am using IO::Uncompress::Unzip module for this. I have my perl script as below:

#!usr/bin/perl
use IO::Uncompress::Unzip qw(unzip $UnzipError);
use strict;
my $propath ="/home/test/prroot/Projects/";
my $proj = "/home/Ras/projectroot/projects.txt";
my @projlist = `cat $proj`;
foreach my $pr(@projlist){
chomp($pr);
my $projname = $pr;
my $projtemp = $pr;
$projname =~ s/ /\_/g;
my $replace1 = "%28"; #escaping special characters from project name
my $replace2 = "%29";
my $replace3 = "%26";
my $replace4 = "%2C";
$projname =~ tr/ /_/;
$projname =~ s/\(/$replace1/g;
$projname =~ s/\)/$replace2/g;
$projname =~ s/\&/$replace3/g;
$projname =~ s/\,/$replace4/g;
chomp($projname);
my $dir = $propath.$projname;
chomp($dir);
my @res = glob "$dir/*.zip";
my @res1 = split '/',$res[$#res];
my $out = chdir $dir;
my $input = "$res1[$#res1]";
my $output = "/home/Ras/projectroot/xmlres/result$projname.xml";
my $status = unzip $input => $output, Name => "data";

}

The file /home/Ras/projectroot/projects.txt includes more than 100 project names. For each project name there is a folder under the path /home/test/prroot/Projects/. Inside the projectname folder there are zip files. I need to read particular file named data from the zip file. I am able to read the output for 13 files as /home/Ras/projectroot/xmlres/result$projname.xml. But after that no result. Please help me on this.


Solution

  • Unzip was giving data error. I did a modification in my script and it helped.

    my $status = `unzip -p $input "data" > $output`
    

    By adding above line replacing unzip $input => $output, Name => "data" helped in solving the issue. Without going for extraction of zip file, it is just reading the data content and i am able to meet the requirement. Thanks for all your help