Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

dynamic scalar values and "strict"
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:
PHP:
my $month 5; my $day 7; my $year 2005; my $params "?"; my @list = qwmonth day year ); foreach my $name (@list){     $params .= "&".$name."=".${$name}; } print $params;
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?

Report this thread to moderator Post Follow-up to this message
Old Post
duffman
05-09-05 09:12 PM


Re: dynamic scalar values and "strict"
Hi,

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

Report this thread to moderator Post Follow-up to this message
Old Post
displeaser
05-23-05 02:15 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Forum Jump:
All times are GMT. The time now is 09:45 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.