#!/usr/bin/perl use strict; use warnings; my @params = (); while ( my $param = shift ) { push @params, $param; } unless ( scalar @params == 4 ) { print "$0 \n"; exit; } my ( $inputFile, $blockSize, $blockLabel, $outputFile ) = @params; print "Input seems to be valid. Now I will try reading the contents of $inputFile..."; open INPUT, '<', $inputFile or die $!; open OUTPUT, '>', $outputFile or die $!; my $sequence = ''; while ( ) { chomp; next if ( /^\s*$/ ); next if ( /^>/ ); $sequence .= $_; } print "done.\n"; my $pos = 0; my $index = 0; print "The sequence has ", length($sequence), " bases. Now I will try breaking it into segments, each of size $blockSize bases.\n"; while ( $pos < length($sequence) ) { $index++; print OUTPUT ">$blockLabel$index\n"; print OUTPUT substr($sequence, $pos, $blockSize) . "\n"; $pos += $blockSize; } close OUTPUT; close INPUT; print "Successfully generated $outputFile.\n";