>>>>> "CO" == Chas Owens <chas.ow...@gmail.com> writes:

  CO> On Fri, May 28, 2010 at 01:05, Uri Guttman <u...@stemsystems.com> wrote:
  CO> 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).
  CO> snip

  CO> This seems like an overcomplicated regex to me, what is the benefit of
  CO> doing this over

  CO> my ($foo) = $string =~ /(.*?)-/; # $foo will be undef if there is
  CO> no match

the negated char class is usually faster than most similar methods. i
just like it as it says what i really want - a string without any - chars.
also anchoring helps too in saying this string must be at the beginning
(he wants the first field).

the OP said null and he didn't specify a null string or undef. i did
chastise him about that term.

  CO> In fact, there appears to be a bug in your code: the 1 or more
  CO> modifier (+) is outside of the parentheses, so you only get the last
  CO> character of the string.

that is correct. it was untested code.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to