Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop iterator variables not localized within the loop #317

Open
kylemhall opened this issue Mar 11, 2024 · 0 comments
Open

Loop iterator variables not localized within the loop #317

kylemhall opened this issue Mar 11, 2024 · 0 comments

Comments

@kylemhall
Copy link

kylemhall commented Mar 11, 2024

When a variable is used in a FOREACH loop, it's value after the loop will be the last value of the loop.

For example, if we have a variable @letters containing a, b, and c:

[% SET x = "x" %]
[% x %] <!-- will print "x" -->
[% FOREACH x IN letters %}
  [% x $]
[% END %]
[% x %] <!-- will print "c" -->

Contrasted with Perl:

my $x = "x";
foreach $x ( @letters ) {
  say $x;
}
say $x; # will print "x"

I think a reasonable solution would be a configuration option ( or a keyword ) to localize the loop variable.

@kylemhall kylemhall changed the title Loop iterator variables not localized with the loop Loop iterator variables not localized within the loop Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant