Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Renaming a Zip file with a user input variable

by mayank646 (Initiate)
on Aug 06, 2012 at 18:23 UTC ( #985789=perlquestion: print w/ replies, xml ) Need Help??
mayank646 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I am trying to rename a zip file with the user input. I have tried but when i am giving the variable its making a file with the vairiable name only like $abc not with the value stored in the variable.
#!/bin/perl use strict; use warnings ; use Archive::Zip; my $zip_file = 'file.zip' ; my $zip = Archive::Zip-> new (); $zip ->addTree( 'c:/zip'); $zip ->writeToFileNamed( $zip_file ); if (-e $zip_file) { print "Archive created successfully!"; } else{ print "Error in archive creation!"; }
Instead of $zip_file being hardcoded i want to take user input for the zip file name. I am using the following code
#! usr/bin/perl use Archive::Zip; # Getting Details print "Enter the Folder Name \n"; $rn = <>; print "The details are as follows: \n"; print "Release Name is *** $rn *** \n"; print "Business Unit is *** ABC *** \n"; print "Environment is *** ABC *** \n"; # Taking Backup my $zip_file = 'file.zip'; my $zip = Archive::Zip-> new (); $zip ->addTree( 'c:/zip'); $zip ->writeToFileNamed($zip_file); if (-e $zip_file) { print "Archive created successfully!"; } else{ print "Error in archive creation!"; }
here i am taking the input from the user and storing it in a variable $rn now i want to make the zip file with the name stored in the variable $rn.

Comment on Renaming a Zip file with a user input variable
Select or Download Code
Re: Renaming a Zip file with a user input variable
by toolic (Chancellor) on Aug 06, 2012 at 18:30 UTC
    shift, then call your script with the file name as an argument.
    my $zip_file = shift;
Re: Renaming a Zip file with a user input variable
by aitap (Deacon) on Aug 06, 2012 at 19:46 UTC
Re: Renaming a Zip file with a user input variable
by rpnoble419 (Pilgrim) on Aug 06, 2012 at 21:33 UTC
    Where are you getting the the user input from when you go into production this code? You do not want to use any web form data directly as this may open your code up to a security issue.
      Hi I am using the following code
      #! usr/bin/perl use Archive::Zip; # Getting Details print "Enter the Folder Name \n"; $rn = <>; print "The details are as follows: \n"; print "Release Name is *** $rn *** \n"; print "Business Unit is *** ABC *** \n"; print "Environment is *** ABC *** \n"; # Taking Backup my $zip_file = 'file.zip'; my $zip = Archive::Zip-> new (); $zip ->addTree( 'c:/zip'); $zip ->writeToFileNamed($zip_file); if (-e $zip_file) { print "Archive created successfully!"; } else{ print "Error in archive creation!"; }
      here i am taking the input from the user and storing it in a variable $rn now i want to make the zip file with the name stored in the variable $rn.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://985789]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-08-23 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (174 votes), past polls