in reply to "when" and replacements

The given ... when construct does a smart match ~~ on the expression after the when EXCEPT in the following cases: Regex-replacements are not in that list, but a negated expression is, therefore your !! trick worked.

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^2: "when" and replacements
by John M. Dlugosz (Monsignor) on May 07, 2011 at 07:08 UTC
    I'm postulating that it ought to be added to that list. It "feels like" the plain match, and adding the =~ directly "feels like" the $_<10 case.
      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

        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.

        Yeah, thats the reason why I never use give/when and prefer the for/if/elsif/last workaround.

        Cheers Rolf