Title: RE: Page generation tweeking

Thanks to $Bill for the help... his solution actually made it generation of the page quicker =) below is the final solution:

my @array = qw(102345 102356 102375);
my $count = '';
my $output_htmlvar = '';
fopen(FILE, "$memberdir/memberlist.txt");
My @memberlist = <FILE>;
fclose(FILE);

foreach my $stuffs (@array){
    fopen(MAILDATA, "$stuffs.mail");
    my @notify = <MAILDATA>;
    fclose(MAILDATA);
    chomp(@notify);
    my %notify = map { $_ => 1 } @notify;
    $output_htmlvar .= "<select name='name' multiple size='3'>";
    foreach my $curmem (sort @memberlist) {
                $curmem =~ s/[\n\r]//g;
                &FormatUserName($curmem);
                #$tmp_error .= "checking $curmem with the value of " . $notify{$curmem} . "<br>\n";
                if(exists $notify{$curmem}){
                        $output_htmlvar .= qq~<option selected value="$curmem">$curmem</option>~;
                        $count++;
                } else {
                        $output_htmlvar .= qq~<option value="$curmem">$curmem</option>~;
                }
        }
        $output_htmlvar .= "</select>";
}
print $output_htmlvar . "\n";
-----Original Message-----
From: Farrington, Ryan [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 23, 2003 9:41 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: 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