Code Comments
Programming Forum and web based access to our favorite programming groups.hi- i have a bunch of variables that i get data into via cgi. because i'm using strict, they all have "my" infront of them. what i'm trying to do is create a string that i can pass to another cgi of a ll the variables. eg ?&month=$month&day=$day&year=$year. now, i was thinking i could very easily just create an array with the names of the scalars, and loop though and put the values in the string. something like this:first of all, because of the "my"'s, the values aren't visible using this dy namic method or some reason. saying print $month inside the foreach works, but ${$name} does not, for some reason... secondly, when i run it using "use strict", i get an error: "Can't use string ("month") as a SCALAR ref while "strict refs" in use" are there ways to get around this?PHP:my $month = 5; my $day = 7; my $year = 2005; my $params = "?"; my @list = qw( month day year ); foreach my $name (@list){ $params .= "&".$name."=".${$name}; } print $params;
Post Follow-up to this messageHi,
The following works as you appear to want it.
use strict;
use warnings;
my $month = 5;
my $day = 7;
my $year = 2005;
my $params = "?";
my @list = qw( month day year );
foreach my $name (@list){
$params .= "\&".$name."=\$".$name;
print "$params\n";
}
print $params;
#wanted: ?&month=$month&day=$day&year=$year
#printed: ?&month=$month&day=$day&year=$year
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.