tbone,
There is a command in Unix called tee which allows you to pipe your output to two different locations. IO::Tee is a CPAN module that allows you to select multiple locations. I do not know if it is any more efficient from a speed perspective as I haven't looked under the hood, but it certainly would be more efficient in programming time.

Hope this helps - cheers - L~R

Update: Ok so I am sick with the flu and I misread "one of 30 files" to be 30 files. So now what can I offer since all kinds of people have replied with applicable solutions?

allolex suggested using subs for repeated pieces of code. I would suggest using a sub for a different reason.
You could use one sub to open all the files and another sub to determine which file handle to select based off the data and then just use print in the main code.

#!/usr/bin/perl -w use strict; # Some code to build your complex hash OpenFiles(); foreach my $n (keys %emp){ my $print = CheckData($n); if ($print) { select $print; print $emp{$n}{'Emp'}; } } sub OpenFiles { mkdir "reports", 0755 || warn "Cannot make reports director: $!"; chdir ("reports") || die "couldn't change to directory : $!"; # All the open statements } sub CheckData { return "A" $emp{$_[0]}{'Emp'} if $emp{$_[0]}{'Org'}=~/ABC/; # etc }

Obviously this code could be cleaned up a bit, but I felt bad for having misread your post and not providing anything useful. With a little work - you pass two arguments to your sub, one is the value to check and the other determines which type of check to perform. This way you could do more than just check the 'Org' value.

Cheers - L~R


In reply to Re: efficiently printing to 30 files by Limbic~Region
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.