[Melbourne-pm] Unix / Perl

Shlomi Fish shlomif at iglu.org.il
Sun Dec 16 12:47:16 PST 2007


On Sunday 16 December 2007, Mirko Fluher wrote:
> Could someone help with this mixture of Unix and Perl.
>
> foreach $_ (`tree -isuDRf /dir1/fileserver/dir2/documents`)
> {
>         next if(/^\/dir1/);
>         ($line1, $line2) =
> /(.*?)\/dir1\/fileserver\/dir2\/documents(\/.*$)/; $line1 =~ tr/[]//d;
>         $_ = $line1;
>         ($userid, $size, $month, $day, $year) =
> /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/; print
> "$userid,$size,$month,$day,$year,$line2\n";
> }
> # to run this prog.
> # ./make_index_docu_csv.pl|sort +1 -rnt, >
> /dir1/fileserver/dir2/documents/documents_index.csv
>
> I would like to have the whole thing in perl ... the problem I have at the
> moment is that 'tree' truncates userid  .. :(
> I have some perl handing directories and files but and bits. Having problem
> getting userid, size time together; not to mention the sorting.
>
> Sorry if this is poor perl... I am not a professional.
> thanks if you can point to a good direction.

Instead of reading the output of "tree", you should use File::Find ( perldoc 
File::Find ) or one of its newer and better non-core alternatives:

* http://search.cpan.org/dist/File-Find-Object/

* http://search.cpan.org/dist/File-Next/

This should make your job much easier.

Regards,

	Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish      shlomif at iglu.org.il
Homepage:        http://www.shlomifish.org/

I'm not an actor - I just play one on T.V.


More information about the Melbourne-pm mailing list