Hi, I am person trying to learn programming and sometimes I am confused at what is bad code?

Can you guys please read my method below and answer if this is really bad coding? or point me to a book/website to learn what is good/bad practice at coding?
1) I know duplicate code is bad... so is my code below bad? as I have some duplication.
2) I also know one method should do one function only, my function below does three things.
a) create http connection
b) foreach through the tokens
c) determine with another function addDaily()/addTest() to see if the term should be added to an array list

my method takes a string $daily_test and calls different part of codes depending on the String value
44 sub constructList($release, $daily_test) { 45-52 Logic to handle getting a HTML page 53 if ($res->is_success) { 54 my @tokens = split('\n',$res->as_string); 55 my @List = (); 56 57 if($daily_test == "daily"){ 58 foreach my $token (@tokens){ 59 if($token =~ m/HREF="([a][^\/]*)/i) { 60 my $extracted = $1; 61 if ($1 !~ m/win/i){next;} 62 if (addDaily($extracted) == 1) { 63 push(@List, $extracted); 64 } 65 } 66 67 } #end foreach 68 69 } #end if 70 71 elsif ($daily_test == "test"){ 72 my $atLeastOneMatch = 0; 73 foreach my $token (@tokens){ 74 if($token =~ m/HREF="([a][^\/]*)/i) { 75 my $extracted = $1; 76 if ($1 !~ m/win/i){next;} 77 if(addTest($extracted) == 1){ 78 push(@List, $extracted); 79 } 80 } 82 } #end foreach

I could have turn this code to... less duplication but maybe a bit more unclear?
58 foreach my $token (@tokens){ 59 if($token =~ m/HREF="([a][^\/]*)/i) { 60 my $extracted = $1; 61 if ($1 !~ m/win/i){next;} 57 if($daily_test == "daily"){ 62 if (addDaily($extracted) == 1) { } elsif($daily_test == "test"){ 62 if (addTest($extracted) == 1) { } 63 push(@buildList, $extracted); 64 } 65 } 66 67 } #end foreach
Thanks!

In reply to How to write good code? by ahhlun

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.