in reply to greping for names

IMHO substr() works faster than regexp:
while(<>) { print if(substr($_,-3,2) eq ".c"); }

Replies are listed 'Best First'.
Re: Re: greping for names
by moxliukas (Curate) on Jul 19, 2002 at 14:43 UTC

    However IMHO this approach is more fragile. I am not sure how this would work on different platforms, because new line is two characters wide on some platforms and only one character wide on the others.

    I might be picky, but if you are really going for speed, use single qoutes istead of double (I know in reality it makes almost no difference, and I'm just being picky ;)

      For the record, ".c" will get optimized to '.c', so it really doesn't matter. Consider
      % perl -MO=Deparse -e 'print ".c";' -e syntax OK print '.c';

      Cheers,
      Shendal