blackadder has asked for the wisdom of the Perl Monks concerning the following question:

Hi all

I have written the script below (with a great help from Browser_UK and other holly brethren here),...
The script works well, but I have been teased by colleges in other branch that they can perform the same operation manually and much faster. Basically, the script obtains the size, number of files and folders of a given path. However if more than one path is supplied then the script will obtain the information of one path and then moves to the second path and so on. Where as manually this operation can be done simultaneously - i.e. right clicking on a selected folder then properties and repeating this process on as many folders as you can fit on the screen. My question is, can this be achieved in Perl script? Can I instruct Perl in my script to obtain the information on the two folder paths that I have supplied simultaneously? And is this what's known as Forking? I am not sure on where to start to look into the possibilities on getting my script to "multi-task" if it’s the correct way of putting it. And as ever your Perls of wisdom are highly appreciated. Any improvements and modifications - to conserve memory are most welcome.

Many Thanks

Btw : In a nut shell - I am migration and getting rid of every M$ server we have here - so it’s a holly operation for me - and migrating all user / data shares and application data to a SAN/NAS environment, using Linux datamovers, that attaches EMC SAN/NAS (disks are housed in Symmetric and the fibre channels patched on the Connectrix - DART is used to move the data). Netbios names will be created for the server that I am getting rid off and using EMC tools for moving huge amounts of data. If anyone has done something similar to this (I was informed this project has only been done in the US) then your comment will also be highly appreciated.
AUTOLOAD; require 5.006; $|++; use strict; use warnings 'all'; #use diagnostics; use Win32::OLE qw[in]; use vars qw/@LoH/; for my $Path (@ARGV) { my $Match = {}; my $fso= Win32::OLE->new( 'Scripting.FileSystemObject' ); my @folders = $fso->GetFolder( $Path || die"No 'TargetPath' was fo +und\n" ); my $fss = $fso->GetFolder($Path); $Match->{path} = $Path; my $Size = $fss->size( ); $Match->{size} = $Size ; my ($fCount, $sCount) = (0,0); print "\nPlease Wait"; while( @folders ) { print "."; my $folder = pop @folders; $fCount += $folder->Files->Count; $sCount += $folder->SubFolders->Count; for my $subFolder ( in $folder->SubFolders ) { $fCount += $subFolder->Files->Count; push @folders, $_ for in $subFolder->SubFolders ; $sCount += $subFolder->SubFolders->Count; } } $Match->{files} = $fCount; $Match->{folders} = $sCount; print "\n\n\nSize of $Path = $Size byte\n\nFiles : $fCount, Folde +rs : $sCount\n\n"; push @LoH, $Match; } # From this point and below I am checking if the two paths match - so +migration is successfull. exit() if ($#LoH < 1); if ($LoH[0]->{size} == $LoH[1]->{size} && $LoH[0]->{files} == $LoH[1]- +>{files} && $LoH[0]->{folders} == $LoH[1]->{folders}) { print "\n[ MATCH ]\n"; } else { print "\nNOT MATCHED\n" }
Cheers.

Replies are listed 'Best First'.
Re: Getting a script to do 2 process simultaneously.
by chromatic (Archbishop) on Jul 29, 2003 at 16:57 UTC

    In general, forking and multi-threading won't speed up non-blocking algorithms unless you have a multiprocessor system and your program can take advantage of multiple processors. This doesn't look like one of those occasions.

    Not being a Windows programmer, I merely suspect you could hoist the OLE constructor out of the loop for a minor speed boost:

    my $fso = Win32::OLE->new( 'Scripting.FileSystemObject' ); for my $Path (@ARGV) { my $Match = {}; );

    You'll also avoid one-character buffer flushes if you re-enable buffering on STDOUT. Just about everything else looks like a micro-optimization to me, and I can't benchmark it. Insert hand-waving here.

      I see,...I have changed my code based on your recommendation and it seems be faster…thanks a lot.
Re: Getting a script to do 2 process simultaneously.
by NetWallah (Canon) on Jul 29, 2003 at 21:04 UTC
    Hi, blackadder - love that name, and yes, I'm a Rowan Atkinson fan, but I did not care much for his recent movie "Johnny English" - anyway - that is completely OT.

    Back in the real world, It seems that you have re-invented the "diruse" program that comes with the Win2k resource kit.

    To test if it is worth converting to multi-tasking, you could run multiple copies of your program, or multiple copies of "diruse", and see if it takes less total time than running serially.

    Here is a small program to get you started on multi-threading.

      Thanks for your help pal,...Rowan Atkinson cannot do wrong,..but I agree with you I didn't think much of his "Johnny English" charactor...but Anyway. Cheers.