in reply to Set variables from m//

It's a precedence problem
m/^(\s)?exten => (35\d\d)[^;]+;(.*)/ && ( my ($extension,$name) = ($2, +$3) );

but conditionally executing a my is not allowed and makes no sense. You want

my (undef, $extension, $name) = m/^(\s)?exten => (35\d\d)[^;]+;(.*)/;

Better yet, get rid of the needless capture

my ($extension, $name) = m/^(?:\s)?exten => (35\d\d)[^;]+;(.*)/;

Why are parens being used at all?

my ($extension, $name) = m/^\s?exten => (35\d\d)[^;]+;(.*)/;

Replies are listed 'Best First'.
Re^2: Set variables from m//
by ebarrere (Initiate) on Jun 24, 2009 at 02:33 UTC
    Ah, perfect!

    Won't the second example capture the wrong backreferences though?

    As for the parens, I guess you're right; that will just force it into an array context unnecessarily, no?

    Thanks!

      Won't the second example capture the wrong backreferences though?

      I don't see any backreferences.

      I don't see a problem. The first capture will be assigned to undef (i.e. dropped), the second will be assigned to $extension, the third will be assigned to $name.

      As for the parens, I guess you're right; that will just force it into an array context unnecessarily, no?

      I meant the parens around \s. It was like doing $z=($x)+($y); instead of $z=$x+$y;