in reply to Re^2: a MooseX Q that's driving me up the wall :)
in thread a MooseX Q that's driving me up the wall :)

When you say that you don't recommend the numbered capture globals, do you mean in general or specifically when dealing with MooseX? Do you always use your own variables for regex captures? Why? Not being critical, I just like learning and I'm still firmly an early intermediate Perl programmer (by my own guesstimate).
In general. I always store the return value of the matched regex (usually in lexical variables), which eliminates a lot of confusion: you know in what scope the variable storing the captured value is, unlike with the globals, and you can do more regex matching without worrying about overwriting previous values. Also, it's simply unnecessary to do
$string =~ /$pattern/; my $match_foo = $1; my $match_bar = $2;
when you can do

my ($match_foo, $match_bar) = $string =~ /$pattern/;

The relevant programming patterns I use the most probably look something like like

if (my ($foo, $bar) = $input =~ /$pattern/) {

and

my @matches = grep { condition } map { /(foo)(bar)/ } @data;

Replies are listed 'Best First'.
Re^4: a MooseX Q that's driving me up the wall :)
by tj_thompson (Monk) on Dec 03, 2010 at 18:52 UTC
    I like it...I was never a big fan of the capture variables. I'll probably lift your patterns and tweak 'em a bit. Thanks!