> >
> > Can anyone help with this????
> > I have the following array:
> > 1,10400000209458..
> > ####WRITE CONTENTS OF AN ARRAY TO OUTPUT FILES####
> > for ($i=0; $i < $num_of_files; $i++){
> > open(OUT,">$file_$seq_num.txt");
> > foreach $item (@temp_array){
> > #
> > # I NEED SOME LOGIC HERE
> > #
> > ($row_num,$prepaid_card_num) = split(/,/,$item);
> > print OUT "$row_num,$prepaid_card_num\n";
> > } #end of foreach loop
> > close(OUT);
> > $seq_num = $seq_num+1;
> > } #end of for loop
> >
> >
> > If I wanted to break this up into 3 files, and max
> number of lines
> > in each
> > file is 2(in this case 2 files w/ 2 rows, 1 file with 1 row).
> > How can I code this???
> >
>
Boris
My first suggestion does not work. So much for rushing to post :) anyway I
tested the below code and it works:
-----------
# subsitute with your array
my @array = qw ( foo bar baz boz box );
my $file = 'out';
my $num =1;
my $cnt = 0;
my @tmp;
foreach my $line (@array) {
# your row or line stuff here
$tmp[$cnt] = $line;
++$cnt;
if ($cnt == 2) {
dmp($file.$num, [EMAIL PROTECTED]);
# print "@tmp\n";
++$num;
$cnt = 0; undef @tmp;
}
}
# dump remaining if there is any
dmp($file.$num, [EMAIL PROTECTED]) if @tmp;
# print "@tmp\n";
sub dmp {
my $file = shift;
my ($a) = shift;
open(F, ">$file") or die "can't open: $!";
for (@$a) { print F "$_\n" };
close F;
}
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.9 - Release Date: 1/6/2005
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>