On Fri, May 28, 2010 at 01:05, Uri Guttman <u...@stemsystems.com> wrote: snip > $foo = $string =~ /^([^-])+-/ ? $1 : '' ; > > that will grab something from the start to the first - and grab it. if > it matched it will assign it to $foo, otherwise assign ''. (and '' is > called the null string, not null. perl has no null things unlike > databases). snip
This seems like an overcomplicated regex to me, what is the benefit of doing this over my ($foo) = $string =~ /(.*?)-/; # $foo will be undef if there is no match or my $foo = $string =~ /(.*?)-/ ? $1 : ""; # $foo will be "" if there is no match In fact, there appears to be a bug in your code: the 1 or more modifier (+) is outside of the parentheses, so you only get the last character of the string. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/