Just what the (code) doctor ordered

Ovid on 2007-10-29T17:18:24

After noticing a bunch of duplicated code, I realized that a particular value which needed to be munged only if it was set could be refactored as follows:

$message &&= $cgi->p($message);

I always forget about that construct, but when you need it, it's great!


Why have I never seen that before

ajt on 2007-10-30T09:17:32

That is so cool and useful, why have I not seen it before? I must re-read my Perl books, I must have missed tonnes of stuff like that.

Re:Why have I never seen that before

Ovid on 2007-10-30T10:19:36

In 5.10, I don't think there's going to be a corresponding feature for this:

$value //= $default;

You still have to write:

$value = $cgi->p($value) if defined $value;

Re:Why have I never seen that before

ajt on 2007-10-30T12:51:20

This is one of the Perl 6 ideas that everyone wants back-porting I think.

I see that &&= is explained on page 92 of my Programming Perl 2nd edition. Not coming from a c background I missed the utility of some of these.