in reply to Template::Toolkit: defined on aggregate item vs. defined on variable

arrays start with 0, so if you add another element, .1 is defined, so I think its not a bug

$ tpage tt2-defined-bug.txt group 1 g 1 group.0 1 group.1 1 no bug $ cat tt2-defined-bug.txt [%# tpage --compile_dir=goner tt2-defined-bug.txt -%] [% group= ["one","two"]; g = group.1 %] group [% IF group.defined %] 1 [% ELSE %] 0 [% END %] g [% IF g.defined %] 1 [% ELSE %] 0 [% END %] group.0 [% IF group.0.defined %] 1 [% ELSE %] 0 [% END %] group.1 [% IF group.1.defined %] 1 [% ELSE %] 0 [% END %] [% IF g.defined != group.1.defined %]Seems like a bug! [% ELSE %]no bu +g[% END %]
  • Comment on Re: Template::Toolkit: defined on aggregate item vs. defined on variable
  • Download Code

Replies are listed 'Best First'.
Re^2: Template::Toolkit: defined on aggregate item vs. defined on variable
by choroba (Cardinal) on Aug 05, 2016 at 22:11 UTC
    > so if you add another element, .1 is defined

    The question is why g.defined != group.1.defined when the array has one element only.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      Because arrays start at 0? So group.1 is not defined? And the condition is true?

      if( 1 ne "") { print "Seems like a bug! BUT IT IS NOT BUG\n"; }
        But why is g defined, when g = group.1 and, as you said, group.1 is not defined?
        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re^2: Template::Toolkit: defined on aggregate item vs. defined on variable
by flowdy (Scribe) on Aug 05, 2016 at 21:18 UTC

    In general you're right. In this case, I just posted a simplified example to pm. In my real-word situation I have to tell apart defined or undefined second part of a tuple in view logic. This is where the shown weirdness taught me better not to give long.paths.through.data.structures simple names to use more than once. Or at least not to include the tail component in the assignment.