in reply to Isolating DNA cont.
A general comment on developing software that works for me (and I suggest it whenever I can), is to always create balanced operations or braces, then go back and fill in the middle. So you would start with your boilerplate opening:
You would have collected your input, opened and closed the file:#!/usr/bin/perl -w use strict; use diagnostics;
Then you would have added the skeleton of your while loop:my $file = $ARGV[0]; open (my $input, '<', $file) or die("Cannot open file $file: $!"); close ( $input );
Even stopping there, you'd have something that opened a file, read through each record, and closed it. You don't have to remember to finish the loop later, or think about closing the file .. you've already done that, and you can then go back and put the meat into the sandwich.my $file = $ARGV[0]; open (my $input, '<', $file) or die("Cannot open file $file: $!"); while($input>) { } close ( $input );
Adding the if statement (without a condition) brings us to this:
To me, that's way easier than writing the opening part of a brace or an operation, then later, trying to remember what I have left to go back and clean up.my $file = $ARGV[0]; open (my $input, '<', $file) or die("Cannot open file $file: $!"); while($input>) { if () { } } close ( $input );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Isolating DNA cont.
by kcott (Archbishop) on Dec 22, 2018 at 11:29 UTC | |
by hippo (Archbishop) on Dec 22, 2018 at 11:47 UTC | |
by talexb (Chancellor) on Dec 22, 2018 at 21:15 UTC | |
by kcott (Archbishop) on Dec 22, 2018 at 12:25 UTC |