in reply to Re^2: Howto strip 42 from comma separated list using s///
in thread Howto strip 42 from comma separated list using s///

It's a trick, I'll admit. In Perl, && returns the right-hand operand if the left-hand one is true, and the left-hand operand if the left-hand one is false. X && Y returns X if X is false, and Y if X is true (regardless of Y's truth value!).

Thus, in my regex, a comma is only inserted if both $1 and $2 are true. $1 && $2 is only true when $1 and $2 have commas in them (otherwise, at least one of them is empty, and thus the empty string is returned).


Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
  • Comment on Re^3: Howto strip 42 from comma separated list using s///