For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > February 2006 > using variable in param









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author using variable in param
Adriano Allora

2006-02-21, 7:55 am

Hi all,

I need to obtain some values (passed with a form) without knowing their
names (but I know these variable names correspond to names of some
files.

So, I tried to write something like this:

opendir(QUERY,
"/Users/adrianoallora/Sites/corpora/VALICO/indici_testa/") or $errtex =
$!;
@interrogabili = readdir(QUERY);
foreach $elem (@interrogabili)
{
next if $elem =~ /^\..*/;
$elem = $home->param($elem);
}

Why the $home->param($elem) line doesn't work? All the rest of the
code works very well (It open effectively the directory, store all the
entries in the array, read each array item...)

Any help is soo much appreciated.

alladr



|^|_|^|_|^| |^|_|^|_|^|
| | | |
| | | |
| |*\_/*\_/*\_/*\_/*\_/* | |
| |
| |
| |
| http://www.e-allora.net |
| |
| |
**************************************

Wiggins d'Anconia

2006-02-21, 6:55 pm

Adriano Allora wrote:
> Hi all,
>
> I need to obtain some values (passed with a form) without knowing their
> names (but I know these variable names correspond to names of some files.
>
> So, I tried to write something like this:
>
> opendir(QUERY,
> "/Users/adrianoallora/Sites/corpora/VALICO/indici_testa/") or $errtex = $!;


The above "or" condition doesn't die, or at least break the execution
loop in some way. It should.

> @interrogabili = readdir(QUERY);
> foreach $elem (@interrogabili)
> {
> next if $elem =~ /^\..*/;
> $elem = $home->param($elem);
> }
>


You haven't shown us the declaration of $elem, I suspect that is the
issue. And since you haven't shown us the declaration I would have to
guess you aren't using,

use strict;
use warnings;

And you should be.

$elem is getting clobbered each time through the loop with a new value,
from the file list, then a new value from CGI (assuming it is defined).

You need to adjust where you are storing the values to keep all of them.
Or you could just get the full list, see Vars() in the perldoc for CGI.

http://danconia.org


> Why the $home->param($elem) line doesn't work? All the rest of the code
> works very well (It open effectively the directory, store all the
> entries in the array, read each array item...)
>
> Any help is soo much appreciated.
>
> alladr
>

David Dorward

2006-02-21, 6:55 pm

On Tue, Feb 21, 2006 at 12:22:39PM +0100, Adriano Allora wrote:
> opendir(QUERY,
> "/Users/adrianoallora/Sites/corpora/VALICO/indici_testa/") or $errtex =
> $!;


So you set a variable if the directory couldn't be opened ...

> @interrogabili = readdir(QUERY);


.... but then carry on and try to read the directory anyway?

> foreach $elem (@interrogabili)
> {
> next if $elem =~ /^\..*/;
> $elem = $home->param($elem);
> }
>
> Why the $home->param($elem) line doesn't work?


You don't define $home anywhere.


--
David Dorward http://dorward.me.uk

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com