Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Syntax error

by graff (Chancellor)
on Feb 11, 2014 at 05:47 UTC ( #1074343=note: print w/ replies, xml ) Need Help??


in reply to Re: Syntax error
in thread Syntax error

Just to give you an idea of how little effort it should take to do the thing that your script does, here's a version that:

  • allows the user to specify all inputs and options at the command line, so the script knows what to do based on command-line args;
  • uses a hash instead of a set of separate scalar variables;
  • uses loops for input and output.
#!/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"; }
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.


Comment on Re^2: Syntax error
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1074343]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2015-07-04 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls