For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2006 > Re: Print to new file for each results









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Print to new file for each results
Mumia W.

2006-08-29, 9:57 pm

On 08/29/2006 06:32 PM, Ron McKeever wrote:
> I am try to use part of someones elses code that creats the data file which prints out like this:
>
> ip|result|deptA|data
> ip|result|deptB|data
> ip|result|deptC|data
>
> My goal instead of having all the data in one big file is to loop this and create a file for each result.
> So I would have a deptA.out file with deptA info then a deptB.out
> file with dept b info and etc...
> [...]


Although this is very different from your program, it should
give you the general idea:

use strict;
use warnings;
use File::Slurp;
use File::Spec::Functions;

my @departments = q{
192.168.14.0|88|Sales|Richard Throop
192.168.16.0|90|Accounting|Juliet Rosenblatt
192.168.20.0|91|Logistics|Mark Mane
192.168.24.0|94|Security|Marlon Johnson
} =~ m/^\s*(.*)$/mg;

# print join "\n", @departments;
my $dir = catfile($ENV{HOME}, qw(tmp tmp));

foreach my $info (@departments) {
my $fname = (split /\|/, $info)[2];
$fname = catfile($dir, $fname);
print $fname, "\n";
write_file $fname, $info . "\n";
}



__HTH__
:-)

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com