in reply to how to find all lines which do not start with something

TIMTOWTDI - without regexp:
my @new = grep { index $_, 'QKC_' } @orig;
index returns 0 (i.e. false) if the string starts with 'QKC_', so those lines will not be returned by grep

Replies are listed 'Best First'.
Re^2: how to find all lines which do not start with something
by ambrus (Abbot) on Sep 17, 2004 at 09:13 UTC

    This is a nice trick, but I guess it will have to search through the entire line, not only the beginning, so it can be a bit slow.

    Possibbilities are:

    my @new = grep { rindex $_, 'QKC_', 0 } @orig;
    or simply
    my @new = grep { substr($_, 0, 4) ne 'QKC_' } @orig;
Re^2: how to find all lines which do not start with something
by gaal (Parson) on Sep 17, 2004 at 08:44 UTC
    Tiny note: if you're favoring index over a regexp because of speed, then you should also prefer to use grep in comma form instead of with a BLOCK:
    my @new = grep index($_, 'QKC_'), @orig;