Title: Page generation tweeking

Ok I have a page that reads 2 files into arrays. Pretty simple stuff like this:
        open(FILE, "file1.txt");
        @file1 = <FILE>;
        close(FILE);
       
        open(FILE, "file2.txt");
        @file2 = <FILE>;
        close(FILE);

Now file1 contains a complete list of users. And file2 contains a list of specific users. What I really want in the long run is to output the complete user list into a <select></select> form on a webpage... Below is what I currently have:

--- CODE ---
        $count = 0;
        MEMBER:foreach my $curmem (@memberlist) {
                $curmem =~ s/[\n\r]//g;
                my $there = 0;
                NOTE:foreach my $note (@notify){
                        $note =~ s/[\n\r]//g;
                        if($note eq $curmem){
                                $there = 1;
                                last NOTE;
                        }
                }
                if($there){
                        $memberlist_htmlvar .= qq~<option selected value="$curmem">$curmem</option>~;
                } else {
                        $memberlist_htmlvar .= qq~<option value="$curmem">$curmem</option>~;
                }
        }
--- END CODE ---

Now my problem is this: the above code works fine when I have to write it 3-4 times. But when I have it being written more then that the page slows down drastically. Ideally what I would like is a single variable that generates the option list once then have some dynamic way of checking it against the @notify array and marking it selected if it exists. BTW each time I get to the notify section I have to read a different file depending on where I am at in the loop. So the memberlist stays constant and the notify is dynamic. Ex:

--- bad code no flames =)---
##before initial loop starts generate the member list with a variable I want filled in when I make reference to the variable

foreach my $curmem (@memberlist) {
        $curmem =~ s/[\n\r]//g;
        $memberlist_htmlvar .= qq~<option $hash{$curmem} value="$curmem">$curmem</option>~;
}
##during loop
        %hash = ();
        NOTE:foreach my $note (@notify){
                $note =~ s/[\n\r]//g;
                $hash{$note} = " selected ";
        }
        Print $memberlist_htmlvar; # I would like this to output the memberlist_htmlvar but have the $hash{$curmem}
                                           #filled in with the new variables


Anyone have thoughts?

Reply via email to