When you say you "find it's too heavy", what makes you think this?

Where in your code is a loop and what do you want to remove?

Note that you can always replace unless(...) by if( not ... ).

Personally, I have the impression that it is not you who finds that code "too heavy" but your teacher or supervisor. Maybe you should go to them and ask them more about what they don't like with your code. Maybe they suggested that you replace the three unless statements with a loop.

If you want to use a loop, I suggest you first print out the three statements and mark with a text marker in one colour the things that are identical between the three statements and then with a text marker of a different colour the things that are different between the three statements. Then you ideally review your course material on loops and find out how you can use a loop to go over the things that are the same and apply the things that need to change for each statement.


In reply to Re: Simplify code in Perl with "unless" loop by Corion
in thread Simplify code in Perl with "unless" condition by Chaoui05

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.