>
> Can anyone help with this????
> I have the following array:
> 1,10400000209458
> 2,10400000328655
> 3,10400000847094
> 4,10400001030406
> 5,10400002093756
> I need to create a script that goes through this
> array(@temp_array), and
> creates various output files with N rows in each file.
> Here's what I have
> so far.
> ####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???
>
Hi Boris
Try something like below, I did quick and did not have time to test, but the
idea should be there. still have to figure out how to handle the last file
with less than 2 rows (while statement) as you will probably get an empty
line
-----------
# populate your array
my @temp;
my $file = 'out'; my $num =1;
foreach (@temp) {
# array slicing here
$cnt = 0;
my $fh = open_new($file$num);
while ($cnt < 2 ) {
print F $someline;
++$cnt;
}
close $fh;
++$num;
}
sub open_new {
my $file = shift ;
local *F;
open(F, ">$file") or die "can't open: $!";
return *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>