[Israel.pm] Using variables

bc.other bc.other at gmail.com
Tue Jan 6 08:25:19 PST 2009

OK, I will explain

I got 2 variables: $var1 = 100 and $var2 = 200
And I got another variable $digit = 1

I need a way to print $var1 using $digit and string "var"
I tried ${"var" . $digit} but it didn't work for me,
I tried $var{$digit} - but it will try look for hash value - nnoooo
I tried $var${digit} - but it's an error mistake....:-(

The reason I need it, because I need to loop on different variables (same
name, different digits)
and check their value against something....and I wanted to do that using a
for/while loop...


-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf
Of Gabor Szabo
Sent: Tuesday, January 06, 2009 5:55 PM
To: Perl in Israel
Subject: Re: [Israel.pm] Using variables

On Tue, Jan 6, 2009 at 5:33 PM, Chanan Berler <chananb at centerity.com> wrote:
> Hello All,
> I have the following prog:
> my $digit = 1;
> my $var1 = 100;
> my $var2 = 200;
> And I need to print $var1, $var2 - but using the $digit concatenated with
> the word 'var'.
> Can anyone help me? Suppose to be an easy task - but I got a blackout

I did not understand. Could you show us what would be the expected
output int the
case you showed us?

Perl mailing list
Perl at perl.org.il

More information about the Perl mailing list