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: Peter J. Acklam
Subject: Re: finding .m files using 'locate'
Date: Tue, 19 Jul 2005 17:41:29 +0200 (CEST)

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

reply via email to

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