On Fri, Feb 22, 2002 at 10:34:06AM -0800, David Rogal wrote:

> foreach $dir (@directories) {
> 
>     foreach $file (sort keys %items) {
> 
>         if $item{$file} eq $dir {
> 
>             # work on it
> 
>         }
> 
>     }
> 
> }

If this were real code, I would restructure it first.  You are sorting
keys %items on each iteration of @directories for no reason.
I claim that the following code achieves the same result with less work.

for $dir (sort @directories){
    if (exists($items{$dir})){
       #work on it
    }
}

If keys %items is smaller than @directories, there are gains in further restructuring.

my %directories = ();
#turn the array entries into hash keys, using a hash slice
@directories{@directories} = (1) x @directories;

for my $file (sort keys %items){
    if (exists($directories{$file})){
       #work on it
    }
}

 
> How do I get at the value of the current iteration of the outer 
> TMPL_LOOP so that I can test against it and deal with the correct data? 
> Be as explicit as possible with your response.

HTML::Template does not provide a loop index. You'll have to create one in perl and
pass it along as another hash key. In general, if something can be easily
done in perl, there's no reason to push it into the templating system.
Let me know if this response is not explicit enough.

-Gyepi Sam 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to