{"id":268,"date":"2021-09-03T02:01:04","date_gmt":"2021-09-03T02:01:04","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/programming-how-to-zip-the-file-using-perl-21789-html"},"modified":"2021-09-03T02:18:08","modified_gmt":"2021-09-03T02:18:08","slug":"programming-how-to-zip-the-file-using-perl-21789-html","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/how-to-zip-the-file-using-perl\/21789.html","title":{"rendered":"How to zip the file using perl"},"content":{"rendered":"<p>Hi all,<\/p>\n<p>I am very new for Perl, I tried to zip the file using the following script<br \/>\n#!perl -w<\/p>\n<p>use strict;<br \/>\nuse File::Find;<br \/>\nuse Archive::Zip qw( :ERROR_CODES :CONSTANTS );<\/p>\n<p>my $dir = &#8216;c:\/siva&#8217;;<br \/>\nmy $zip = Archive::Zip-&gt;new();<br \/>\nmy $zipped;<\/p>\n<p>$zipped = $zip-&gt;addDirectory( $dir );<br \/>\n$zipped-&gt;desiredCompressionMethod( COMPRESSION_DEFLATED );<br \/>\nfind(&amp;zip_file, $dir);<br \/>\ndie &#8216;write error&#8217; unless $zip-&gt;writeToFileNamed( &#8216;logs.zip&#8217; ) == AZ_OK;<\/p>\n<p>sub zip_file {<br \/>\n$zipped = $zip-&gt;addFile( $File::Find::name );<br \/>\n}<\/p>\n<p>But i got the following errors. Could you please help me for solve this problem.<\/p>\n<p>cannot call method &#8220;desiredCompressionMethod( COMPRESSION_DEFLATED )&#8221; on the undefined value at c:perlsitelibArchiveZipArchive.pm line 249<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","meta":{"inline_featured_image":false,"iawp_total_views":31},"question-category":[55],"question_tags":[],"class_list":["post-268","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=268"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=268"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=268"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}