Paul Seamons wrote:
Of course, that wasn't exactly what you were asking, but it does present
a practical solution when you want to:

        {say $_ for =<>}.() if $do_read_input;

Which I just verified works fine under current pugs.

Thank you.

Hadn't thought of that.  I think that is workable.

But it also brings the question: If you can do it ugly [1] easily, why not allow for it do be done prettily [2] ?

say $_ for =<> if $do_read_input

It relates to some old problems in the early part of the RFC/Apocalypse process, and the fact that:

        say $_ for 1..10 for 1..10

Was ambiguous. The bottom line was that you needed to define your parameter name for that to work, and defining a parameter name on a modifier means that you have to parse the expression without knowing what the parameters are, which is ugly in a very non-stylistic sense.

To resolve that, the modifiers are limited to one per statement. There's nothing that can be done about:

        {say $_ for 1..10}.() for 1..10

but at least then you are going out of your way to shoot yourself in the foot, so presumably you knew the risks. Others who are not so bold will write:

        for 1..10 -> ($a) {
                for 1..10 -> ($b) {
                        say $b;
                }
        }

And ambiguity is gone.

Reply via email to