Fellow Monks, --
I'm playing with a directory parsing based on example 4.3 from HOP v.1:
### Iterate.pl use strict; use warnings; use Iterator_Utils; # --------------------------------------------------------- sub interesting_files { my $is_interesting = shift; my @queue = @_; return Iterator { while (@queue) { my $file = shift @queue; if (-d $file) { opendir my $dh, $file or next; my @newfiles = grep {$_ ne "." && $_ ne ".."} readdir $dh; push @queue, map "$file/$_", @newfiles; } return $file if $is_interesting->($file); } return; }; } # -------------------------------------------------------- sub $is_WrappedXml { my $file = shift; return 1 if $file =~ /WrappedXml.{0,5}\.xml/i; return; } # -------------------------------------------------------- # MAIN my $WrappedXml_file = interesting_files(\$is_WrappedXml, '.'); while (defined($file = NEXTVAL($WrappedXml_file))) print $file; }
where
### Iterator_Utils.pm package Iterator_Utils; use base Exporter; @EXPORT_OK = qw(NEXTVAL Iterator); %EXPORT_TAGS = ('all' => \@EXPORT_OK); sub NEXTVAL { $_[0]->() } sub Iterator (&) { return $_[0] } 1;
When running program Iterate.pl i get the error:
C:\tmp>Iterate
Illegal declaration of anonymous subroutine at
C:\tmp\Iterate.pl line 26.


Any ideas why the Iterator {...} construct is illegal in this context ??

Best regards,
Allan Dystrup

In reply to HOP Iterator Ex4.3-- Illegal declaration by ady

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.