Hello ganeshPerlStarter,
The IO::Uncompress::Unzip::unzip function also accepts a reference to a string for the input:
#! perl
use strict;
use warnings;
use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
my $file = 'data.zip';
open(my $fh, '<', $file)
or die "Cannot open file '$file' for reading: $!";
binmode $fh;
my $input;
{
local $/ = undef;
$input = <$fh>;
}
close $fh
or die "Cannot close file '$file': $!";
my $output;
my $status = unzip \$input => \$output
or die "Unzip failed: $UnzipError\n";
print "Status: $status\n";
print "Unzipped text:\n\n>>>$output<<<\n";
I created a text file named “data.txt” and zipped it to “data.zip” using 7-Zip. The above script reads the zipped file data into the scalar $input, then correctly unzips it when passed a reference to the scalar (string) — \$input — as the input parameter.
Hope that helps,