Boris Volf wrote:
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???

#!/usr/bin/perl use warnings; use strict;

my @temp_array = (
     '1,10400000209458',
     '2,10400000328655',
     '3,10400000847094',
     '4,10400001030406',
     '5,10400002093756',
     );

my $N = 2;

####WRITE CONTENTS OF AN ARRAY TO OUTPUT FILES####
for my $seq_num ( 1 .. $num_of_files ) {
open OUT, '>', "$file_$seq_num.txt" or die "Cannot open $file_$seq_num.txt: $!";
print OUT splice @temp_array, 0, $N;
close OUT;
}


__END__




John -- use Perl; program fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to