[Israel.pm] Using variables

Gaal Yahas gaal at forum2.org
Tue Jan 6 07:55:04 PST 2009


Can you clarify what your desired output is? I'm not sure I understand
you correctly, on the face of it you're looking for:

  print join "var$digit", $var1, $var2;

....but I don't know why you'd want that :-)

Or, perhaps, you mean you wanted to preface each variable with its
name? It's much better to use a hash in this case:

  my %data = (
    var1 => 100,
    var2 => 200,
  );

  # There's more than one way to do this; here's one.
  while (my($key, $value) = each %data) {
    print "$key is set to $value\n";
  }

Hope this helps.


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 ..wow
>
> Thanks
> Chanan
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>



-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/



More information about the Perl mailing list