in reply to efficiently printing to 30 files

Your approach (the way you've written your loop and so forth) seems ideally suited for using symbolic references. Bear in mind that symbolic references must be used with considerable caution. Using them carelessly can lead to hard-to-track-down bugs. But your code can be greatly shortened:

mkdir "reports", 0755 or warn "Cannot make reports director: $!"; chdir ("reports"); # As someone else pointed out, / makes the path abs +olute. my %group = ( ABC => 'A', DEF => 'B', # You can have whatever mappings you want here. # They don't have to be single letters, either. # But don't have one called STDOUT or cetera. DEFAULT => 'DEFAULT'); no strict refs; # WARNING: This will annoy the 'use strict or die' people. foreach my $f (values %group) { open $f, ">group$f.txt"; } foreach my $n (keys %emp) { if (not defined $group{$emp{$n}{'Org'}}) { warn "Group $emp{$n}{Org} missing from \%group, " . "using DEFAULT group.\n"; $group{$emp{$n}{'Org'}} = $group{'DEFAULT'}; } print $group{$emp{$n}{'Org'}} $emp{$n}{'Emp'}; }

This does pretty much exactly what you were doing, in pretty much exactly the same way, but with less code, because you only have to ennumerate all your cases once instead of twice.

If you aren't comfortable with references in general then you should avoid this solution and instead rewrite your whole approach, using one of the other suggestions. You don't want to use symbolic refs unless you can follow what they're doing.


for(unpack("C*",'GGGG?GGGG?O__\?WccW?{GCw?Wcc{?Wcc~?Wcc{?~cc' .'W?')){$j=$_-63;++$a;for$p(0..7){$h[$p][$a]=$j%2;$j/=2}}for$ p(0..7){for$a(1..45){$_=($h[$p-1][$a])?'#':' ';print}print$/}

Replies are listed 'Best First'.
Re: Re: efficiently printing to 30 files
by tbone (Beadle) on Mar 07, 2003 at 14:06 UTC
    You guys are the best! Thanks so much for the advice..Now I just have to figure out which one is the best. Thanks again