Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: trouble understanding boss's code

by Util (Priest)
on Jul 20, 2011 at 17:16 UTC ( [id://915686]=note: print w/replies, xml ) Need Help??


in reply to trouble understanding boss's code

It is a common practice, although not always the best idea. I often see $r or $ret (or @r, %r, @ret, %ret, etc) as the name of whatever variable will ultimately contain the value(s) to be returned. Often, the variable should instead be named in a way that makes the name itself self-document its contents or its use. I cannot tell if this would be one of those cases.

Untested, equivalent code (just because I read via refactoring):

sub read_dt2 { my ($path) = @_; open my $IFH, '<', $path or die "cannot open file '$path': $!"; my %mysterious_hash_keyed_by_nucleotide; for my $nucleotide ( qw( A C G T ) ) { local $_ = <$IFH>; $mysterious_hash_keyed_by_nucleotide{$nucleotide} = [split]; } close $IFH or warn "cannot close file '$path': $!"; return \%mysterious_hash_keyed_by_nucleotide; }

Replies are listed 'Best First'.
Re^2: trouble understanding boss's code
by DanielM0412 (Acolyte) on Jul 20, 2011 at 18:01 UTC
    thanks, i will definately try it out

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (10)
As of 2024-04-18 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found