Home: Perl Programming Help: Intermediate:
Dymanic Variable with Perl



200120022003
New User

Mar 24, 2010, 11:40 PM


Views: 3897
Dymanic Variable with Perl

I am writing a login script as follow:

====================================
my $login = param('login');
my $password = param('password');
my @newarraytom = ('name','company','email');

@selected_array = "@newarray".$login;
print @selected_array;
====================================
or directly print "@newarray".$login;

I want to use the $login variable to select appropriate array (@newarraytom), this case login as tom.

Can perl do that ? Thank you !


7stud
Enthusiast

Mar 25, 2010, 3:16 AM


Views: 3891
Re: [200120022003] Dymanic Variable with Perl


Code
use strict; 
use warnings;
use 5.010;

my %info_for = (
tom => ['ibm', 'abc@xxx'],
betty => ['google', 'xyz@xxx'],
);

my $name = 'tom';
say "@{$info_for{$name}}";

--output:--
ibm abc@xxx



(This post was edited by 7stud on Mar 25, 2010, 3:18 AM)