Perl script error to split huge data one by one.

Below is my perl script:

#!/usr/bin/perl
open(FILE,"$ARGV[0]") or die "$!";
@DATA = <FILE>;
close FILE;
$join = join("",@DATA);
@array = split( ">",$join);

for($i=0;$i<=scalar(@array);$i++){
        system ("/home/bin/./program_name_count_length MULTI_sequence_DATA_FILE -d /home/target_directory >> output.txt ");
}
exit;

My input file (MULTI_sequence_DATA_FILE) content:
>seq_1
HIACT
>seq_2
ADSAFASFASF
>seq_3
ASFDFSDFGSDGF
>seq_4
ASDRTY
.
.
.

My desired output file (output.txt) content:
>seq_1 5
>seq_2 11
>seq_3 13
>seq_4 6
.
.
.

Unfortunately, my perl script error causing I get this output file (output.txt) content:
>seq_1 5
>seq_1 5
>seq_1 5
>seq_1 5
.
.
.

My purpose want to let the perl script and split all input data header by header and then run the program and all output in one file (output.txt).
Unfortunately, my perl script error causing that it only consider the first header throughout the end :frowning:
Thus my output file only got the detail of first header read :frowning:
Thanks a lot for any advice and point out what mistakes I did :frowning:
Besides perl script, any other alternative solution like awk or sed, I also appreciate it ^^
Thanks again :slight_smile:

$cat test.pl

#! /usr/bin/perl 
open(FILE,$ARGV[0]) or die $!;

while(<FILE>){
        chomp;
        if (/>seq/){
                $next=<FILE>;
                chomp $next;
                $c=split(//,$next);
                print "$_ $c\n";
        }
}

$perl test.pl inputfile > outputfile

thanks a lot, skmdu
Your perl script worked perfectly for my input file :slight_smile:
Thanks a lot.
Besides that, can I ask you that how can I edit my perl script to let it only run my "program_name_count_length" program to archive the same goal?
Thanks again, skmdu ^^

what does your program program_name_count_length do?

If possible paste that script? It would be better to help you to edit your perl script.

Hi skmdu,
sorry ya because the program actually is a binary mode.
I can't edit it as well, only can run it :frowning:
Thus I try to write a script to let each header data run the same program one by one and output it to a output file.
I found out that "system call" command able to archive this goal. But need to write a script to let the program run the data one by one.
really thanks for your help, skmdu.

I got try one way to archive the same goals but it is not a good solution and no effective :frowning:
First of all. I split all the content into a lot of file based on its header. After then I run each of the file with the desired program and cat each output result to a combined file at the end.
It is worked as well. Just not a good solution :frowning: