in reply to Re: using split without $junk
in thread using split without $junk

my ( $keep ) = $string =~ /^(.*?)\|/;
Because you know where you want to stop matching, you really should drop .* and use a negated character class instead:
my ( $keep ) = $string =~ /^([^\|]+)/;

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: Re: Re: using split without $junk
by davido (Cardinal) on Nov 24, 2003 at 18:53 UTC
    I agree, and actually originally had it as [^|]+ ( | isn't special inside character classes, IIRC). But after hitting "preview" decided that the negated character class method might seem unclear to the OP, so I changed it to the more ubiquitous .*?.

    But your point is valid, that .* and .+ are usually the lazy, slower, and more prone to mistakes ways to do things in pattern matching.


    Dave


    "If I had my life to live over again, I'd be a plumber." -- Albert Einstein