Let me suggest an alternate approach. First get rid of the opendir calls by delegating to File::Find.
and then structure the callback along the lines ofuse File::Find; find(\&eachfile, "/data/");
That's the rough idea, at least -- it needs some cleanup and error handling.sub eachfile { my $path = $File::Find::name; return if -d $path; $path =~ s|^.*/(.+)_logs/|| or return; # or log my $item = $1; if ( $path =~ m|(.+)\.(\d+)$| ) { my($company,$quantity) = ($1,$2); inventory($company, $item, $quantity); return; } # and so on for each remaining case # eventually logging any that you can't handle }
This would seem to me to be a very easy thing for whoever comes along after you to understand and maintain. The most they would need to understand is File::Find, and that's a low hurdle.
Granted, this leaves you with the equivalent of a string if/elseif*/else, but it seems easy enough to follow.
In reply to Re: The dreaded if-elsif-else construct (code)
by dws
in thread The dreaded if-elsif-else construct (code)
by deprecated
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |