Absolutely omit an "unused or useless" else clause. Including it adds clutter to your code making it harder to find the code that does real work and making it harder to see the decision tree that gets you to any particular outcome.

With that in mind there is no need to add extra comments to say "Oh, and I really mean not to have some code here". Do you put a comment at the end of each line to say "This line is not conditional on anything"? The code structure itself should reflect thee intended behaviour. Relying on comments to make that clear will simply lead to trouble when the implementation and comment drift apart - perl doesn't read your comments.

That said, it may be that a better implementation for your code could be something like:

#!/usr/bin/perl use strict; use warnings; use 5.010; my @tracks = map {open my $track, ">", $_ or die "Can't open $_: $!"; + $track} 'track1.txt', 'track2.txt', 'track3.txt'; for my $track (@tracks){ print <$track>; }

or if the "line" numbers are important:

#!/usr/bin/perl use strict; use warnings; use 5.010; my @tracks = (['track1.txt', 1000], ['track2.txt', 5000], ['track3.txt', 20000] +); for my $track (@tracks) { open my $trackFile, ">", $track->[0] or die "Can't open $track->[0 +]: $!"; $track = [$trackFile, $track->[1]]; } for my $track (@tracks) { my ($trackFile, $lines) = @$track; print <$trackFile>; }

Whenever you catch yourself doing xx1 = ...; xx2 = ...; ... think instead about arrays and loops. It makes the code clearer and much much easier to maintain.

True laziness is hard work

In reply to Re: if-elsif-else (?) by GrandFather
in thread if-elsif-else (?) by rnaeye

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.