in reply to Re: lazy evaluation of sub arg
in thread lazy evaluation of sub arg

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.

Replies are listed 'Best First'.
Re^3: lazy evaluation of sub arg
by chromatic (Archbishop) on Dec 17, 2008 at 17:47 UTC
    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.