Seems like variables declared outside foreach, initialized inside foreach will not persist its data.
Consider this example :
[-
$myVar;
foreach my $item (qw/item1 item2 item3/) {
$myVar = $item;
}
print $myVar # This will print undef, I expect it to print item3
-]
How do I make this work with foreach loop?
Change the
print $myVar
sentence toprint OUT $myVar;
OUT filehandle is tied to Embperl's output stream. You can use also a[+ $myVar +]
block instead of printing to OUT.