Note that this version will count any character inventory you give it; if the input happens to contain something other than ACGT, you'll get the quantity of occurrence for all the letters that occur in the data.#!/usr/bin/perl use strict; # enforce variable declarations use warnings; # enable warnings my $Usage = "Usage: $0 [sequence.file]\n (reads stdin if no file name + is given)\n"; die $Usage unless ( -p STDIN or ( @ARGV and -f $ARGV[0] )); my %counts; # tally of letter occurrences # read lines from named file(s) or from stdin: while (<>) { s/\s+$//; # remove white space (line termination) from end of lin +e for my $ltr ( split // ) { # split into individual characters $counts{$ltr}++; } } # print results: for my $ltr ( sort keys %counts ) { print " Number of $ltr nucleotides: $counts{$ltr}\n"; }
In reply to Re^2: Syntax error
by graff
in thread Syntax error
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |