in reply to Re: Golf this reg ex
in thread Golf this reg ex

japhy, thanks but I'm not sure I understand the /* and the fact that you can have, what appears to be, compounded reg exes. Anyway, I can't get it to work in
my $number = "..2314-1234123."; if ($number =~ /\d/*/^([\d.-]+)$/ ) { print "$1\n"; }
If you have the time, a simple explanation would be educational. TIA

—Brad
"A little yeast leavens the whole dough."

Replies are listed 'Best First'.
Re: Re: Re: Golf this reg ex
by halley (Prior) on Apr 16, 2004 at 14:01 UTC
    perl -MO=Deparse
    my $number = '..2314-1234123.'; if ($number =~ /\d/ * /^([\d.-]+)$/) { print "$1\n"; }
    The original trick is multiplying the first regex result (as a scalar) by the second regex result (as a scalar). That is, 1*1 is true, but 0*1 is false.

    However, since the two regexen aren't being bound to $number in your example, the code actually doesn't work. The second regex is searching $_ for matches instead.

    --
    [ e d @ h a l l e y . c c ]