[sf-perl] Referencing a variable???

David Fetter david at fetter.org
Tue Jul 28 16:32:35 PDT 2009

On Tue, Jul 28, 2009 at 04:09:28PM -0700, Peter Loo wrote:
> Hi All,
> I have done this once before and can't seem to remember how I did it.
> I have 10 program variables namely $parm[1-10].  Then I try to check if they are set using a loop like so:
>   for ( my $x = 1; $x <= $maxParm; $x++ ) {
>     my $parmName = "parm" . $x;
>     if ( $$parmName ) {
>       my ($hardValue, $replaceValue) = split(/~!~/, $$parmName);
>       $sqlString =~ s/~$hardValue~/$replaceValue/g;
>       }
>     }
> $$parmName has no value.  What am I doing wrong?

I'm sorry that this sounds harsh, but the answer to that question is,
"just about everything."

String-mashing to create SQL invites Little Bobby Tables into your
life.  See http://xkcd.com/327/

Instead, use prepare() and execute(), each explained in detail in the
DBI docs. :)


P.S.  Looping constructs in Perl aren't the ones in C.  Use the Perl
ones in Perl programs :)
David Fetter <david at fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter at gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

More information about the SanFrancisco-pm mailing list