As a beginner, I made all of these mistakes and then some. Thank you chromatic for this excelent node, and dominus for the Red Flag papers. While forcing myself to rewrite a script to have them all use strict I came up with the following solutions which may be of benefit to others like me (for most of you this is way too trivial, but this is the voice of a beginner).
To access a number of files in a loop construct, this was my initial attempt:
for ($results = 2; $results <34; $results++) {
my $file="current$results.res";
open (TALLYRESULTS, ">$file") or die ("cant open results f
+ile");
....
}
A common mistake, apparently, which turned out to be easy to avoid:
for ($results = 2; $results <34; $results++) {
my $file="current".$presence.".res";
....
}
Another (double!) 'Red Flag' situation was this:
@tree1=@samples[0..2];
... (another 10 of those)
@tree12=@samples[33..35];
for ($z = 1; $z <= 12; $z++) {
$arrayname="tree$z";
foreach $patch(@$arrayname) {
... do something
}
and solving it taught me a thing or two about hashes:
my %trees = (1 => "@samples[0..2]",
... (another 10 of these)
12 => "@samples[33..35]",
);
while ((my $tree, my $samples) = each (%trees) ){
my @patches = split (/ */, $samples);
foreach $patch(@patches) {
... do something
}
My script now runs under strict, and I'm proud of it ;-)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.