I was using a code from "Perl Hacks", hack-27, but it doesn't works as
expected, and I don't know why.
Any one can explain what it should yield ?
Or am I missing something?
-- cmic. retired sysadmin and Perl user..#!/usr/local/bin/perl use strict; use warnings; use Want 'howmany'; sub multi_iterator { my ($iterator)=@_; return sub{ my $context=wantarray(); return unless defined $context; return $iterator->() unless $context; return map { $iterator->() } 1 .. howmany(); }; } sub counter { my ($from, $to, $step)= @_; $step ||= 1; return sub { return if $from > $to; my $value=$from; $value +=$step; return $value; }; } #main my $counter=counter(1, 10, 3); my $iterator= multi_iterator($counter); my ($un, $deux)=$iterator->(); my $trois=$iterator->(); #should print 1, 4, 7 print "Hack-27 ", $un, ",", $deux, ",", $trois, "\n";
In reply to iterator w/ wantarray() by cmic
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |