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$/}

In reply to Re: efficiently printing to 30 files by jonadab
in thread efficiently printing to 30 files by tbone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.