#!/usr/bin/perl -w

use strict;
use Getopt::Long;

my $withGaps;
if (!GetOptions("withGaps" => \$withGaps)) {
    print "Syntax: fa_length <fasta file> [-withGaps]\n",
        "        -withGaps --> calculate length including gaps (-)\n\n";
    exit 1;
}

my ($c);
while (<>) {
    if (/^>/) {
        print $c, "\n" if defined $c;
        print /^>(.+?)\s/, "\t";
        $c = 0;
    } else {
        $c += s/\w//g;
        if (defined $withGaps) {
            $c += s/\-//g;
        }
    }
}

print $c, "\n";
