Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Seeking help for using Tie : : File in my perl program for counting bases using Active Perl 5.10.1 Build 1007

by GrandFather (Cardinal)
on Jan 30, 2012 at 10:32 UTC ( #950741=note: print w/ replies, xml ) Need Help??


in reply to Seeking help for using Tie : : File in my perl program for counting bases using Active Perl 5.10.1 Build 1007

There is no need at all to use Tie anything for this task. As with many many problems that are attacked using Perl the key is to use a hash. There are bunch of newbie foibles in your code that are worth trying to clean up sooner rather than later. I haven't described the issues explicitly, but have addressed them in the following code. Have a try using the code as a starting point, and please ask about anything you don't understand:

#!usr/bin/perl use strict; use warnings; if (! @ARGV) { print <<HELP; Usage: > basecount.pl <bases file> HELP exit; } open my $dnaIn, '<', $ARGV[0] or die "Can't open bases file $ARGV[0]: +$!\n"; my %counts; my @baseList = qw(A T G C); while (defined (my $line = <$dnaIn>)) { chomp $line; ++$counts{$_} for grep {/\S/} split '', $line; } my $bases; my $errors; $bases += $_ for @counts{@baseList}; $errors += $_ for map {$counts{$_}} grep {! /[ATGC]/} keys %counts; print "Total bases: $bases\n"; print join (', ', map {"$_: $counts{$_}"} @baseList), "\n"; print "Errors: $errors\n" if $errors;

Note that the code is untested and in any case I may not have understood what you are counting.

True laziness is hard work


Comment on Re: Seeking help for using Tie : : File in my perl program for counting bases using Active Perl 5.10.1 Build 1007
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-10-02 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (49 votes), past polls