D
Dave
Hi,
When I run the code below, I get the following error message "Can't use
string ("postf1") as a SCALAR ref while "strict refs" in use at
test.cgi line 20"
I searched google, this group's archives, and perldoc. I found a couple
of articles in this group's archives that I think could apply, but I
did not entirely understand them.
Could someone let me know what I need to do in order to dynamically
load variable names and then reference them? In the example below @rows
actually represents a call to a database field which could have an
infinate number of lines, separated by \n. The field is split using \n
and then variables assigned to each part of each row. Is there a
different way to do that?
Thanks,
Dave
-------------------
#!/usr/bin/perl
use strict;
use warnings;
my @rows=('f1|v1','f2|v2');
my ($postf1,$postv1,$postf2,$postv2);
my $rowcount=@rows;
if ($rowcount>0)
{
my $x=0;
foreach my $row(@rows)
{
$x++;
my $field="postf$x";
my $value="postv$x";
my ($name,$content)=split(/\|/,$row);
${$field}=$name;
${$value}=$content;
}
}
print "f1: " . $postf1 . " v1: " . $postv1 . "\n";
print "f2: " . $postf2 . " v2: " . $postv2 . "\n";
When I run the code below, I get the following error message "Can't use
string ("postf1") as a SCALAR ref while "strict refs" in use at
test.cgi line 20"
I searched google, this group's archives, and perldoc. I found a couple
of articles in this group's archives that I think could apply, but I
did not entirely understand them.
Could someone let me know what I need to do in order to dynamically
load variable names and then reference them? In the example below @rows
actually represents a call to a database field which could have an
infinate number of lines, separated by \n. The field is split using \n
and then variables assigned to each part of each row. Is there a
different way to do that?
Thanks,
Dave
-------------------
#!/usr/bin/perl
use strict;
use warnings;
my @rows=('f1|v1','f2|v2');
my ($postf1,$postv1,$postf2,$postv2);
my $rowcount=@rows;
if ($rowcount>0)
{
my $x=0;
foreach my $row(@rows)
{
$x++;
my $field="postf$x";
my $value="postv$x";
my ($name,$content)=split(/\|/,$row);
${$field}=$name;
${$value}=$content;
}
}
print "f1: " . $postf1 . " v1: " . $postv1 . "\n";
print "f2: " . $postf2 . " v2: " . $postv2 . "\n";