in reply to backward split

Seems like reverse split reverse reverse is working a bit too hard.

my $s = 'foo.bar.foobar'; my ($var1, $var2) = $s =~ m[(^.*)\.(.*?$)]; print $var1, $var2; foo.bar foobar

Note: The greedy .* in the first capture and the non-greedy .*? in the second.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


Replies are listed 'Best First'.
Re^2: backward split
by Aristotle (Chancellor) on Jun 01, 2003 at 12:04 UTC
    Making the second star nongreedy does not change any of the matches this pattern will find and only causes the regex engine to jump through extra hoops.

    Makeshifts last the longest.