How to Zip Files Using Perl

PERL is an interpreted scripting language popular with many system administrators for automating their jobs. It's core libraries contain functions for easily achieving many common computing tasks, including creating zip archive files.

Instructions

    • 1

      Create a new text file named "zip.perl" using either Notepad or another editor of your choice. Ensure that the extension is ".perl" and not ".txt."

    • 2

      Import the Zip library by pasting the following command:

      use IO::Compress::Zip qw(zip $ZipError) ;

    • 3

      Specify the files to be zipped and the name of the .zip file by pasting the following code:

      $input = '<*>';

      $output = 'file.zip';

      This will zip all files in the current directory. There are a variety of options you can use at this step. For example:

      $input = '<*.txt>'

      This will zip all files in the current directory that end with the txt file extension.

    • 4

      Perform the zip operation by pasting the following command:

      zip $input => $output

      or die "zip failed";

      If you like, you can add a few optional parameters to this step. For example, if you wish to append the data to the end of the zip file rather than create an all new one, use the following:

      zip $input => $output, Append=>1

      or die "zip failed";

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured