Hello, On Mon, 07 Jun 2010, Cristian Rodríguez wrote:
El 26/05/10 01:47, David C. Rankin escribió:
total=$(ls $budir/bashrc-* | wc -l)
total=$(python -c "import glob; print len(glob.glob('<your pattern>'))"
You have higher level tools, use them :)
perl -e 'print scalar @{[glob("*.txt")]};'
or
perl -e 'print $#{[glob("*.txt")]} + 1;'
or
perl -e 'print scalar @{[<*.txt>]};' ### [1]
or
perl -e 'print $#{[<*.txt>]}+1;'
There's a reason "perlgolf" exists :)
But actually, it'd probably be reasonable, to write the rest of the
script in python resp. perl as well. ;) As above is "perl" core only,
it's pretty fast. On this (500MHz Athlon) box, perl 5.10.0 is even
faster than python 2.5. The fastest of a about a dozen calls each:
python: real 0m0.137s
perl: real 0m0.053s
I'd guess it's the file-lookup + 'import' of 'glob' in python.
-dnh
[1] that actually is parsed as
use File::Glob (); print scalar @{[glob('*.txt')];};
as '