in reply to Re: Smart Substrings
in thread Smart Substrings

Your first code snippet is a good example of bringing out the regex chain-gun when a simple substr would do:
my $short = substr $string, 0, 15;
This is equivalent, but faster and more readable. Don't use a regex unless you actually need it.

Your second snippet doesn't split on words. You would need to change the \s* to a \s+ for it to do that, but then it would break on a starting word greater than 15 chars.

I don't mean to offer harsh criticism, but one of my pet peeves is seeing regexes used when a simple index/substr would do.

   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
Re: Re: Re: Smart Substrings
by Pin (Novice) on Apr 03, 2001 at 20:48 UTC

    Why would you keep a peeve as a pet? Wouldn't a dog or a cat be more fun?

    (Sorry, couldn't resist ;^)