Re: Print to new file for each results
- From: mumia.w.18.spam+nospam@xxxxxxxxxxxxx (Mumia W.)
- Date: Tue, 29 Aug 2006 18:51:31 -0500
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__
:-)
.
- Prev by Date: Re: splitting strings
- Next by Date: Re: accessing other array indexes other than the current of a foreach
- Previous by thread: Can't create 2d array in Perl
- Next by thread: Print to new file for each results
- Index(es):
Relevant Pages
|
Loading