RPrinceton
Programmer
Hi,
In the book "Learning Perl" it appears that the language supports variable interpolation. What I want to do is dynamically change the name of a variable in a loop so that when the Perl interpreter sees it, it will appear to have a new name with each iteration. Please review the following code that is not working.
my $i; # field name index
my $base = ""; #base field name
my $base1 = "abc";
my $base2 - "def"
while ($i <= 1)
{
$i = $i + 1;
$base = '$base'.$i;
print LOG "Field: $base\n";
^
|__ I would think 1st iteration would
be named $base1 and in the log "abc"
2nd iteration would be named $base2
and in the log "def"
}
Here is what I end up in the log:
Field: $base1
Field: $base2
I am sure there is a little "tweak" to accomplish this.
Please advise.
Thanks in advance.
Regards,
Randall Princeton
In the book "Learning Perl" it appears that the language supports variable interpolation. What I want to do is dynamically change the name of a variable in a loop so that when the Perl interpreter sees it, it will appear to have a new name with each iteration. Please review the following code that is not working.
my $i; # field name index
my $base = ""; #base field name
my $base1 = "abc";
my $base2 - "def"
while ($i <= 1)
{
$i = $i + 1;
$base = '$base'.$i;
print LOG "Field: $base\n";
^
|__ I would think 1st iteration would
be named $base1 and in the log "abc"
2nd iteration would be named $base2
and in the log "def"
}
Here is what I end up in the log:
Field: $base1
Field: $base2
I am sure there is a little "tweak" to accomplish this.
Please advise.
Thanks in advance.
Regards,
Randall Princeton