in reply to Urgent help needed by inexperienced programmers

My gut instinct is to store the user identity in a file associated with a number. When the questionnaire has been validated, delete the line that contains the translation. This of course requires that the adminstrator of the script is scrupulous and does not view the file that associates number to user. This is a simple way to handle it, and may or may not be feasible in a RL situation, but you've already said it's for a class, so in lieu of cookies, that's another option. This is known as storing persistent data, and while it's not exactly the cookbook way, it's under the same idea. (ie - read this to mean, go reread the Perl Cookbook aka the Ram)

As for your questionN -> N. You could duplicate the data from CGI.pm and set it up so that:

Update: The code here is flawed, see Re: Re: Re: Urgent help needed by inexperienced programmers to understand why.

@params = $q->param(); # assuming using OO style of CGI.pm foreach $val @params { if ($val =~ /^question(.+)/) { $$1 = $q->param($val); } }

and now they are accesible via just N, well $N to be fair.

Stick around, and you may see better answers. Remember this is just what first came to my mind.

ALL HAIL BRAK!!!

Replies are listed 'Best First'.
Re: Re: Urgent help needed by inexperienced programmers
by a (Friar) on Dec 07, 2000 at 05:14 UTC
    The external file sounds like a good idea, you'd need to keep the ID number in each of the pages so you can match it up w/ the user at the end ... not secure, of course. I can put a number in my hacked copy of your script too.

    There's been lots of discussion on why $$1 = ... is a *bad* idea; generally it means you're looking at the wrong end of the problem. You could do:

    foreach $val @params { if ($val =~ /^question(\d+)/) { $questions[$1] = $q->param($val); } }
    which'd give you the question vals in an array, indexed by N but ... that's only slightly better. Overwrites if N is in there twice, etc.

    a

      I'd never do it that way. I was just providing a method that would meet spec. There's not even a reason to do what you're suggesting since it's duplication of data (ie - memory issues). But, some caveats to your code. We don't know if N will be integer. We presume it will be, but what about cases 1a, 1b, 1c?

      Furthermore, my code has that problem in the case where $1 = 1. in which case you're evaluating ${$1} -> $1 -> 1;

      My answer was to generally push these guys in the direction proper, and your reply shows why my initial thought of stripping question from N is bad. I hadn't seen that before a, thanks.

      It appears that a lot of people use the ID number, since it appeared on another post as magic cookie. I left a lot of my answer open ended since this is a group project for school, and I think they should be forced to use their heads a little. You are correct about the ID being stored on the questionnaire page, but I figured that it was obvious.

      ALL HAIL BRAK!!!