[Ilugc] PERL assigning variables

  • From: ilugid@xxxxxxxxx (Ashish Verma)
  • Date: Mon Jan 25 12:31:39 2010

Hi,

I am trying to assign values to variable names stored in an array, however
it is not working below is the code. Please see the highlighted text.

Trying to achieve the following:

If user has stored his options in a file, then the code should open that
file, pick the values and assign them to variable names stored in the array
@vrvariables.
*Basically the variables should get assigned from either user input, or from
a stored file.*

CODE


my @myvariables = ('url','realm','username','password','proxy','cookies');
*my @vrvariables =
('$url','$realm','$username','$password','$proxy','$cookies'); # THESE ARE
THE STORED VARIABLE NAMES*
my $varcount = @myvariables;
my $ac = 0;
my $store_file = 'files-dash/cds.html';
sub grab_input
{
        print "Store choice made (Y/N): "; chomp(my $choice = <STDIN>);
        print "URL to access          : "; chomp(my $url = <STDIN>);
chomp(my $url_credentials = `echo $url | cut -d "/" -f3`);
        print "Realm (If required)    : "; chomp(my $realm = <STDIN>);
        print "Username (If required) : "; chomp(my $username = <STDIN>);
        system(`stty -echo`);
        print "Password               : "; chomp(my $password = <STDIN>);
        system(`stty echo`);
        print "\n";
        print "Proxy server           : "; chomp(my $proxy = <STDIN>);
        print "Cookies File to use    : "; chomp(my $cookies = <STDIN>);
        if($choice eq "Y" || "y")
        {
        my %credentials_store = ( url => $url, realm => $realm, username =>
$username, password => $password, proxy => $proxy, cookies => $cookies );
        open(STORE, ">store.txt");
        my $i = 0;
        foreach(%credentials_store)
                {
                        while ($i < $varcount)
                                {
                                        print STORE
$credentials_store{"$myvariables[$i]"}, "\n";
                                        $i++;
                                }
                }
        }
}
sub make_input_global
{
        `cp store.txt temp.txt`;
        open(MKGLB, "<temp.txt");
        my $i = 0;
        while ($stored_var = <MKGLB>)
                                {
*                                        "$vrvariables[$i]" = $stored_var;
#THIS IS NOT WORKING
*                                        $i++;
                                }
        #`rm -f temp.txt`;
}

Other related posts: