in reply to lazy evaluation of sub arg

I wouldn't contact MJD without a complete code sample, and certainly not with similar code.

The following works for me as advertised http://hop.perl.plover.com/Examples/Chap6/Stream.pm
http://hop.perl.plover.com/Examples/Chap6/show-example-2

Replies are listed 'Best First'.
Re^2: lazy evaluation of sub arg
by drbean (Novice) on Dec 17, 2008 at 14:08 UTC
    My problem appears to be the result of where 'sub promise (&) { $_[0] }' is placed in the file. If it is placed after the definition of the upto subroutine which uses it, I get the error message as before. If it is placed BEFORE the definition of the upto subroutine, it works as the book says.

    I didn't think the placement of subroutines mattered in a file. Perhaps the subroutine prototype on the definition of promise is turning it into an anonymous sub.

      Perhaps the subroutine prototype on the definition of promise is turning it into an anonymous sub.

      Prototypes change the parsing of code, and they can only change the parsing of subsequent code. When you declare that a subroutine takes a block argument with a prototype, the lexer has to know that that block represents an anonymous subroutine, not a hash reference.