Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Exercise: DNA Sequence Analyzer with shortcut

What if you would like to provide the user the ability to stop the processing any time she wants even if the file has not finished yet? For example when she found the first match. This can be controlled by the return value of the analyze function. If it is true, stop processing. See the skeleton and the expected output:

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

my $file = 'dna.txt';

my @dna_sequences = read_file(\&analyze_dna, $file);
sub analyze_dna {
    my ($dna) = @_;
    if ($dna =~ /(.)\1/) {
        print "$dna has double $1\n";
        return 1
    }

    return 0;
}

sub read_file {
    ...
    return;
}
GAGATTC has double T