Hello Anonymous Monk,

Have you considered also the possibility of Switch? (Not Recommended)

#!usr/bin/perl use say; use strict; use warnings; # use Benchmark qw(:all) ; # WindowsOS use Benchmark::Forking qw( timethese cmpthese ); sub while_loop { my (@array) = @_; while (defined(my $i = shift @array)){ # This destroys @array, tho +ugh next if ($i % 2 || $i % 3 || $i % 4 || $i % 5); } } sub for_loop { my (@array) = @_; foreach my $i ( @array ) { # This does not destroy the @array next if ($i % 2 || $i % 3 || $i % 4 || $i % 5); } } my $results = timethese(100000000, { For => for_loop( 1 .. 100 ), While => while_loop( 1 .. 100 ) }, 'none'); cmpthese( $results ); __END__ $ perl test.pl (warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) Rate For While For 434782609/s -- -83% While 2500000000/s 475% --

Update: Not a good idea as the monks pointed out. Not recommended it.

Update2: You could also change your for loop to a while loop it is always faster see code example above.

Hope this helps.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: if ... elsif ... else by thanos1983
in thread if ... elsif ... else by Anonymous Monk

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.