in reply to Drop Down Selection #2

First of all, return doesn't work when you are not in a subroutine, so you probably want exit(1);

You are already in a loop for $u... the while is a loop, what you should do is create an array, and push values of $u on it as you get them, so you would do

push @users, $u;
in your loop, that adds values of $u one by one to the array, appending them to the end. Then your call would look like
print $query->popup_menu(-name=>'userid', -values=>\@users);## $u needs loop to pu +ll all company entries from $db
at least, I think that is what you are asking for?
                - Ant

Replies are listed 'Best First'.
Re: Re: Drop Down Selection #2
by koacamper (Acolyte) on May 09, 2001 at 01:18 UTC
    Ant, Thank you for your response to my question. I am still fairly new to CGI scripting, which is why I need to ask the following question: How should the script look with the push added? I've tried multiple ways of inserting the push but I keep getting a 500-Internal Error. I understand this completely:
    print $query->popup_menu(-name=>'userid', -values=>\@users);
    But the part that has me stiffled, is this:
    # open the text database unless(open(PFD,$db)) { &printError("Could not open user database"); exit(1); } # first check if user exist $path=''; while (<PFD>) { chomp; ($u,$p,$path)=split('\|',$_);###$u loop?? how? if ($userid eq $u) { $rc=1; last; } } close(PFD);
    Thank you so much
      # open the text database unless(open(PFD,$db)) { &printError("Could not open user database"); exit(1); } my @users; # first check if user exist $path=''; while (<PFD>) { chomp; ($u,$p,$path)=split('\|',$_);###$u loop?? how? push @users, $u; if ($userid eq $u) { $rc=1; last; } } close(PFD); print $query->popup_menu(-name=>'userid', -values=>\@users);
      That should work, but in your code you do a last if $userid eq $u, which means @users will store all the users in the list until the one that matches $userid... not sure if that is what you want.
                      - Ant
        The presence of an error check is less valuable than the presence of an error check that captures all relevant status information.

        As perlstyle says, including the name of the file you are trying to open and the contents of $! is a substantive style issue. That information is valuable, and when things go wrong you want to have it from the start.

        Thank you very much! That did the trick! I have been working on this for far too long! I sincerely appreciate your assistance.