[ale] 2 Perl questions ?

Geoffrey esoteric at 3times25.net
Wed Dec 15 10:00:42 EST 2004


Courtney Thomas wrote:
> Purpose:
> 
> write a small program that will process all files in a designated
> dir, which contains files and dirs, by examining each file entry and
> sums it to a total, which is less than some arbitrarily entered size,
> [in this case <=650MB since the purpose     is to aggregate chunks of
> the original dir into separate dirs <=650MB for burning to a CD], and
> if the total <=650MB, then, move that entry into the new "burn" dir,
> and continue until a total <=650MB is reached, then stop.
> 
> In this way I can take an arbitrary size dir and allocate it to any 
> number of burn dirs of <=650MB, then burn 'em.
> 
> -------------------------------------------------------------------------
>  2 Problems:
> 
> 1-The compiler is complaining about uninitialed variables within a 
> "while" loop. How do I properly initialize numeric variables within
> the loop ?


Put 'use diagnostics;' at the top of your code to get more info on errors.

Share the code and specific errors.  I suspect you're doing something like:

while () {
	$foo = $bar;
}

where you should have something like:

my ($foo, $bar);

while () {
	$foo = $bar;
}

> 
> 2-I also need to traverse a dir that itself contains dirs, processing
>  each file and dir. How do I traverse such a dir such that....when a
> dir is encountered it is entered and all the files in it are then
> processed, and if necessary drills down through other dirs [howto
> control depth ?]...before returning to the original dir that
> contained files and dirs ?

Perfect case for a recursive call.  Something along the lines of:

sub ParseDir
{

	my $filename = $_[0];

	if (-d $finename ) {
		ParseDir($filename);
	}
	.
	.
	.
}


-- 
Until later, Geoffrey



More information about the Ale mailing list