in reply to Re^2: "when" and replacements
in thread "when" and replacements

To be true, I also had some trouble before I got my head around this given ... when. The whole idea of the default smart match takes some time to getting used to. If I want a smart match, I'll ask for one, explicitly, in all other cases I use something else, explicitly.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^4: "when" and replacements
by John M. Dlugosz (Monsignor) on May 07, 2011 at 08:53 UTC
    using $_ =~ at the beginning of the stuff in parens should be enough to indicate "I don't want a smart match"; evaluate it the same as a mundane if statement, in the same way as the relational operators.

    After all, I might want the single-branch feature of when and have other cases that do use more usual match criteria.

Re^4: "when" and replacements
by LanX (Saint) on May 07, 2011 at 09:01 UTC
    Yeah, thats the reason why I never use give/when and prefer the for/if/elsif/last workaround.

    Cheers Rolf