help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: finding .m files using 'locate'


From: Przemek Klosowski
Subject: Re: finding .m files using 'locate'
Date: Mon, 18 Jul 2005 23:12:05 -0400 (EDT)

   > Sort is not necessary because locate sorts its data.

   Locate sorts the full path, including the filename.  After you strip out 
   the filename, you need to sort again before sending to uniq or you will 
   have problems.  This is output from 'locate':

Me bad---you are right about that.

   [...przemek's method is...] really slow compared to perl.  On
   Solaris, I compared your method with mine and found that yours took
   111.49 seconds and mine took 0.96 seconds

This may be a statement about Solaris more than about the method. On
my Linux box I see that your method is somehow faster, by a factor or
two or so, nowhere near 100 times. I proposed it because it was
simpler to remember and understand. I find that I make hard-to-catch
mistakes when I use regexps, even though I have used Perl since v.2.0
in late eighties.  In fact, there's a mistake in your regexp: 

   s#(^.*)/[^/]+.m#$1#g

the dot before the 'm' should be escaped (the result is OK, but it is
the kind of problems that trip up even seasoned regexp users).  Also,
I believe your code would fail if there was a directory named
/home/dir.m (so would mine, but for a different reason :)

I agree w/you completely about Perl being the only tool one ever needs
("Swiss army chainsaw"). I have eschewed sed, awk and even egrep; in
fact I would have written your

 locate .m | egrep '\.m$' | perl -pe 's#(^.*)/[^/]+.m#$1#g' | sort | uniq
as
 locate .m | perl -ne 'print if s#(^.*)/[^/]+\.m$#$1#' | sort | uniq
        



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]