Q about Coro file::find

Marc Lehmann schmorp at schmorp.de
Wed Feb 1 23:12:25 CET 2012


On Wed, Feb 01, 2012 at 11:27:09AM +0100, Aleksandar Lazic <al-anyevent at none.at> wrote:
> Can I change the following line
> 
>  aio_lstat [$wd, $_] for @$files;
> 
> to
> 
>  aio_lstat $wd, sub {$outhash->{'bytes'} += -s _} for @$files;
> 
> to calculate the bytes in the directory as

Almost, the sub{} should be fine, but you also replaced "[$wd, $_]" (== file
_$ relative to dir $wd), by $wd only. This might work better:

  aio_lstat [$wd, $_], sub {$outhash->{'bytes'} += -s _} for @$files;

Also, you might additionally want to stat dirs (they also take up space),
and, depending on how compatible to "du" you want to be, you should
probably add up (stat _)[12], to get the number of filesystem blocks
actually used (usually in units of 512 bytes).

> OT: Is there a better way to print the elapsed time then this?
> 
> %T = %H:%M:%S
> POSIX::strftime("%T",Time::HiRes::time-$tgesammt ,0,0,0,0,0)

Depends on how you want it printed :) To get timing data, I usually use
the "time" utility, but if the above works for you, what could be better
:)

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\



More information about the anyevent mailing list