From help-request at octave dot org Tue Jul 19 10:42:21 2005 Subject: Re: finding .m files using 'locate' From: "Peter J. Acklam" To: Date: Tue, 19 Jul 2005 17:41:29 +0200 (CEST) ------=_Part_1458_18204363.1121787688931 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit Mike Miller wrote: > > Peter J. Acklam wrote: > > > The -l (ell) option is very useful for one-liners like this > > > > locate "*.m" | perl -ple 's#(^.*)/[^/]+$#$1#' | sort | uniq > > > > which can be simplified to > > > > locate "*.m" | perl -ple 's|/[^/]+$||' | sort | uniq > > Shoter *and* slightly faster! That's because in this case perl doesn't have to store the captured info into the $1 variable and insert it afterwards. > > where the "sort" and "uniq" can be removed by using > > > > locate "*.m" | perl -nle 's|/[^/]+$|| ; print unless $d{$_}++' > > Slightly faster still, but also a little longer. It also saves a few processes. You can micro-optimize the above into ... | perl -nle 's|/[^/]+$||; $d{$_}++ || print' Peter ------=_Part_1458_18204363.1121787688931-- ------------------------------------------------------------- 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 -------------------------------------------------------------