#!/usr/bin/perl -w use strict; use Tie::Array::SubIterator; use HTML::Template; use Devel::Size qw(total_size); my @array= (1..10_000); sub next { my $self = shift; return undef if $_[0] > $#array; return { num => $array[$_[0]], added => $array[$_[0]]+10, subtracted => $array[$_[0]]-10 }; } my @old_method; push @old_method, { "num" => $_, "added" => ($_ + 10), subtracted => $_-10 } for (@array); print "old: ", total_size(\@old_method),$/; print "new: ", total_size(\@array),$/; tie my @data, "DMN::TieArrayForeach", next=>\&next; my $tmpl = q|

|; my $template = HTML::Template->new(scalarref => \$tmpl); $template->param(data => \@old_method,bob=>"outer area"); my $one = $template->output(); $template->param(data => \@data,bob=>"outer area"); my $two = $template->output(); print "identical$/" if $one eq $two;