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

I find it somewhat scary that MooseX seems to be messing with some pretty standard Perl magic. I don't think I've ever seen odd nonstandard behavior from regex captures like that before.

I did notice that the value suddenly shifted to the 'coerce' string. In my more complicated code this is pulled from, I actually saw 'is_subtype_of'. So there's definitely something strange going on in the background. I'm hoping a guru can shed some light on it. I don't like wierd voodo stuff going on that I can't figure out.

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).

  • Comment on Re^2: a MooseX Q that's driving me up the wall :)

Replies are listed 'Best First'.
Re^3: a MooseX Q that's driving me up the wall :)
by Anonymous Monk on Dec 03, 2010 at 17:07 UTC
    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;

      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!