in reply to Idiom for setting variables to empty string if capture is undefined?

Before anything else, let's change the variable names. $a and $b are reserved for sort, lexicalizing them could lead to strange behaviour.

There are several ways how to prevent the warnings. The most common one is to test whether there was a match:

if (my ($x, $y) = 'ab' =~ /(x)(y)/) { print "$x$y\n"; }

Another possibility it to use the convenient defined-or operator (Perl 5.10+ needed):

my ($x, $y) = 'ab' =~ /(x)(y)/; print $x // q(), $y // q(), "\n";
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Idiom for setting variables to empty string if capture is undefined?
by karlgoethebier (Abbot) on Dec 06, 2015 at 22:20 UTC
    "...$a and $b are reserved for sort..."

    Sure, they are.

    "Everything You Always Wanted to Know About $a and $b (*But Were Afraid to Ask)" (freely adapted from Woody Allen)

    But the OP doesn't sort. And what about localizing them in a block if he really wants/needs this variable names for some unknown/weird reasons?

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»