Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: efficiently printing to 30 files

by kelan (Deacon)
on Mar 06, 2003 at 22:23 UTC ( [id://241018]=note: print w/replies, xml ) Need Help??


in reply to efficiently printing to 30 files

Well first, the directory might be getting creating, but you aren't changing to it. You're trying to change to a directory called reports directly under / (root). You should change that to chdir 'reports'; (ie, leave out the leading slash). For the second part, printing to 30 files, how about this:

use IO::File; my %files; $files{A} = $files{B} = $files{C} = IO::File->new('> groupA.txt'); $files{D} = $files{E} = $files{F} = IO::File->new('> groupB.txt'); # etc... for my $n (keys %emp) { print {$files{$n}{Org}} $emp{$n}{Emp}; # ^^^^^^ ^^^^^ # This gets the FH And prints this to it } # Now close the FH's close($file{$key}) for my $key (keys %files);
You might also want to print some kind of separator between the employee info that you print.

kelan


Perl6 Grammar Student

Replies are listed 'Best First'.
Re: Re: efficiently printing to 30 files
by thor (Priest) on Mar 07, 2003 at 00:11 UTC
    Ugh. I know that I wouldn't want to type in 8 open statements. In the spirit of TMTOWTDI:
    #!perl -w use strict; my %hash; my $i = "A"; foreach ("A".."Z") { if ( (ord() - ord("A")) % 3 == 0) { $i++; } $hash{$_} = chr(ord($i) - 1); } foreach my $key (sort keys %hash) { print "$key => $hash{$key}\n"; } __END__ A => A B => A C => A D => B E => B F => B G => C H => C I => C J => D K => D L => D M => E N => E O => E P => F Q => F R => F S => G T => G U => G V => H W => H X => H Y => I Z => I
    Of course, you can insert your IO::File statement in pretty easily. Also, I assume that the pattern of 3 letters to a file holds. YMMV

    thor

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://241018]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-25 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found