Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Now i need to copy data inside the zip files to one .txt file i.e all R1 folder file data should copy and save in one R1.txt file similarly R2 folder file data should save in one single R2.txt file. is it possible to copy data from zipped files??

#!/usr/bin/perl
use File::Copy;
use strict;
use warnings;

print"Enter Folder name 
";
print"File name: ";
chomp(my $Filename=<>);

mkdir "R1";
mkdir "R2";


opendir(DIR,"$Filename") or die "cannot open directory";
foreach my $name (readdir(DIR))
{
next if ($name =~ /^./);
  if($name =~ /R1/) { #compare $name not $Filename
   copy("$Filename/$name", "R1"); # copy the file from folder to R1 directory
   system("cat  $Filename/$name >> R1.txt");
}
elsif($name =~ /R2/){
   copy("$Filename/$name","R2"); ## copy the file from folder to R2 directory
 system("cat  $Filename/$name >> R2.txt");
    }
  }

thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
128 views
Welcome To Ask or Share your Answers For Others

1 Answer

without unzipping the file you can extract the content, the simple and easiest way to do so without using modules is, to use unix command in perl

use strict;
use warnings;
my $text = `unzip -c customer.xml.gz`;
print $text ."
";

AFter extracting the contents, write the same into one.txt file


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...