VingInMedina has asked for the wisdom of the Perl Monks concerning the following question:
A trick I used to use was variable abstraction (holding the name of a vairable inside of a variable). For example I have a set of arrays @a, @b and @c. I have another variable which holds the name of the array I was to look at, say $x. I would set $x to 'b' and then have the array I wanted as @$x.
#!/usr/bin/perl @a = (1, 2, 3); @b = (4, 5, 6); @c = (7, 8, 9); $x = 'b'; print "@$x\n";
Now, this won't work if you use strict in your program.
My question is, what is the correct way of doing this?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Variable Abstraction with strict
by toolic (Bishop) on May 27, 2011 at 19:00 UTC | |
by VingInMedina (Acolyte) on May 27, 2011 at 19:17 UTC | |
by NetWallah (Canon) on May 27, 2011 at 21:35 UTC | |
by NetWallah (Canon) on May 27, 2011 at 19:23 UTC | |
|
Re: Variable Abstraction with strict
by chromatic (Archbishop) on May 27, 2011 at 21:05 UTC | |
|
Re: Variable Abstraction with strict
by Gulliver (Monk) on May 27, 2011 at 20:45 UTC | |
|
Re: Variable Abstraction with strict
by LanX (Saint) on May 27, 2011 at 21:23 UTC | |
|
Re: Variable Abstraction with strict
by CountZero (Bishop) on May 28, 2011 at 12:45 UTC | |
by Anonymous Monk on May 28, 2011 at 16:19 UTC | |
|
Re: Variable Abstraction with strict
by Anonymous Monk on May 27, 2011 at 21:15 UTC | |
|
Re: Variable Abstraction with strict
by catalin.ciurea (Novice) on May 27, 2011 at 23:15 UTC |