Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to get my head around variable interpolation and dereferencing, and all I can say is that I have a headache ;)
Can Perl use the value of one variable as the name of another variable?
For example:
I apologize for the ambiguous code but, I don't have a real world need for this, I'm just trying to answer questions that sprung up while taking a shower.#!/usr/bin/perl -w use strict; my ( @Category, @Cat1, @Cat2, @Cat3, $Sub_Category, $Value ); @Cat1 = qw( a b c ); @Cat2 = qw( 1 2 3 ); @Cat3 = qw( x y z ); @Category = qw( Cat1 Cat2 Cat3 ); foreach $Sub_Category (@Category) { print "$Sub_Category\n"; foreach $Value (@$Sub_Category) { # I'm trying to make Perl see @Cat +1 but, Larry gives me the following error: "Can't use string ("Cat1" +as an ARRAY ref while "strict refs" in use" print "$Value\n"; } } __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dynamic Variables?
by dragonchild (Archbishop) on Feb 28, 2002 at 21:46 UTC | |
by Anonymous Monk on Feb 28, 2002 at 22:46 UTC | |
|
Re: Dynamic Variables?
by patgas (Friar) on Feb 28, 2002 at 22:07 UTC | |
by Anonymous Monk on Feb 28, 2002 at 22:52 UTC |