> 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
This seems to work great, thanks! - Grant > 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. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/