On Tue Mar 03 2009 @ 10:21, Lauri Nikkinen wrote: > Ok, thanks. Now I notice that I did not understand correctly what this > script does. I was trying to print sizes of all directories in the directory > tree. But anyway, I appreciate your kind help!
The line find( sub { #code here}, $dir ) simply runs the code in the subroutine on the directory you specify with the $dir variable. Now let's look at what's in your subroutine: > > > find( sub { -f and ( $size += -s _ ) }, $dir ); That line tests if each item in $dir is a *file* (-f). If it is, then the code continues and adds the size in bytes of that same item to the $size variable. I don't mean to go on and on about this, but the code doesn't match what you're describing you want to do above: you aren't testing for *directories* only for files, and you aren't asking to print out any results. So, as Chas said, your first problem is that you aren't printing out any output. Your second problem is that you aren't gathering total size by directories. Your simply gathering the sizes of all the files in $dir and any subdirectory starting from $dir. The way that File::Find works is a little unusual, and for me at least was initially confusing. You might want to read through this article, which includes successively more complex examples: http://www.stonehenge.com/merlyn/LinuxMag/col45.html -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/