> hmm... I dont consider this to be a bug...
> 
> here you create a global variable called 'gvar'
> > $t->param(gvar     => "global variable");
> 
> here you are creating a loop specific variable called 'gvar'
> >     { loopvar => "GVar should be set",         gvar => "Loop GVar 1" },
> 
> These two 'gvar's are two different variables. 
> 
> In this case
> >     { loopvar => "GVar should be blank again", gvar => undef         },
> 
> you are saying that the loop specific 'gvar' is not part of the loop - ie equivalent 
> to:
>        { loopvar => "GVar should be blank again" }

here is where i think we differ... 

1. $href = { loopvar => "GVar should be blank again", gvar => undef }
to me (and in general perl programming is VERY different from: 
2. $href = { loopvar => "GVar should be blank again" }

In (1), you are explicitely saying that you want "gvar" to be undefined.
In (2), you are not saying that... you are effectively saying that you
don't care what "gvar" is... 

To see how perl treats them differently, here is an example of a very
common function (keys) that returns all the keys in a hash... 

(1) perl  > print "Keys: ". join(',', keys %$href) . "\n";
(1) output> Keys: gvar,loopvar

(2) perl  > print "Keys: ". join(',', keys %$href) . "\n";
(2) output> Keys: loopvar

Another example:

-- test.pl --
#!/usr/bin/perl
my $tvar = "this is a test";
$tvar = undef;
print "Tvar=$tvar\n";
-----------------------------------------
The above prints: Tvar=

Now, so in the same context if "undef" should mean... take the outer
scope, then perl should have ignored my "$tvar = undef" line... 

I think its definitely a bug :-) 
It has infact been flagged before as well... its partially on a thread
at:
http://www.mail-archive.com/[EMAIL PROTECTED]/msg00728.html
although that thread digressed a bit... but this topic has been bought
up a few times... so maybe we can find more threads about it in the
history of the list... 

simran.








> 
> thus requesting the outer global gvar to come into scope.
> 
> Consider:
> 
> t->param(gvar => "Global gvar");
> my $gvar_val;
> my @loop;
> for.... {
>   if (something) {
>     $gvar_val = "Loop GVar 1";
>   } elsif (somethign else) {
>     $gvar_val = "";
>   }
>   my $tmp;
>   $tmp->{loopvar} = ...;
>   $tmp->{gvar} = $gvar;
>   push @loop, $tmp;
> }
> t->param(testloop =>[EMAIL PROTECTED]);
> 
> What would you expect the TMPL_LOOP to do in that example? 
> I would have expected that the third iteration to use the global gvar value.
> 
> Mathew
> 
> 
> > ========================================================================
> > test.tmpl:
> > ----------
> > Global Variable gvar is: <tmpl_var name=gvar>
> > 
> > Loop: <tmpl_loop name=testloop>
> >         loopvar: <tmpl_var name=loopvar>
> >         gvar   : <tmpl_var name=gvar>
> >       </tmpl_loop>
> > ========================================================================
> > test.pl
> > -------
> > 
> > use strict;
> > use HTML::Template;
> > 
> > my $t = new HTML::Template(filename => "test.tmpl", global_vars => 1,)
> > || die;
> > 
> > my $testloop = [
> >     { loopvar => "GVar should be set",         gvar => "Loop GVar 1" },
> >     { loopvar => "GVar should be blank",       gvar => ""            },
> >     { loopvar => "GVar should be blank again", gvar => undef         },
> > ];
> > 
> > $t->param(gvar     => "global variable");
> > $t->param(testloop => $testloop);
> > print $t->output();
> > ========================================================================
> > 
> > When you run test.pl.. you get the following output:
> > ------------------------------------------------------------------------
> > Global Variable gvar is: global variable
> > 
> > Loop: 
> >         loopvar: GVar should be set 
> >         gvar   : Loop GVar 1
> >       
> >         loopvar: GVar should be blank
> >         gvar   : 
> >       
> >         loopvar: GVar should be blank again
> >         gvar   : global variable
> > ------------------------------------------------------------------------
> > 
> > Now, the issue is that "gvar" in the third iteration of the loop,
> > "should have been blank"... i explicitely set it to "undef" in the
> > code.. however, since global_vars was on, it ignored my "undef". 




-------------------------------------------------------
This SF.Net email is sponsored by: SourceForge.net Broadband
Sign-up now for SourceForge Broadband and get the fastest
6.0/768 connection for only $19.95/mo for the first 3 months!
http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to