#!/usr/bin/perl use warnings; @apple=(1 ... 3); $nm=0; foreach my $num (@apple) {$nm++; $output_fle="$nm.txt"; if (-e $output_fle) { open FILE,"$output_fle" or die "Couldn't open file: $!"; $fle=join(" ",); close FILE; $fle=~ s/\s//g; @fle=split(' ',$fle); push @all_file,@fle; } # End of if LOOP for required files: } # Last curly brace of Foreach LOOP for uploading all files: ######################### # Code for each file: ## ######################### $file_no=0; foreach my $each_fle ( @all_file) { $file_no++; @a=split(',',$each_fle); $seq_no=0; foreach my $seq (@a) { $seq_no++; # For each sequence of the file $seq=~ s/,//g; $seq= uc$seq; $seq_len=length($seq); # For testing print"\n Element $seq_no of File $file_no: $seq Length: $seq_len\n"; # push length & each seq to an array: push @names,$seq; push @values,$seq_len; } # End of foreach LOOP for each file: ####################################################### # Find two lowest & two highest values of each file with sequences: ####################################################### use 5.010; use Data::Dumper; use constant IWANT => 2; my @data; my $pos=1; for my $val (@values) { my $name=shift @names; my $rec=sprintf"\n Length %0.1f; Seq: %s",$val,$name; push @data,$rec;} print"\n\nLength (Small to big) with sequences for File $file_no:\n"; @data= sort @data; for(0 .. IWANT-1) {say $data[$_];} print"\n"; print"\nLength (Big to small) with sequences for File $file_no:\n"; for (1 .. IWANT) {say $data[-$_];} ############################ # End Max & Min codes here: ############################# @values=(); # To empty the array @names=(); # To empty the array print"\n######## File $file_no ends ##############\n\n"; } # End of foreach LOOP for all files exit; ########################################