sacked,
The empty list trick, while very cool, is not equivalent to next. Your equivalent for code should look like the following instead:
my @odd; for ( 0 .. 10 ) { push @odd unless $_ % 2; }
The reason I say this is that a map block is like a modifed subroutine that is applied to each item successively in the input list. Like regular subroutines, the last line of evaluated code is the return value. Unlike regular subroutines, you can not force it to return early by using return.

The empty list trick is just preventing the map block from returning a value for that input item - it still has to execut every step in the block first. In the case of next in a for loop, it actually jumps to the next iteration without executing the body of the block.

Cheers - L~R

Update: While I maintain that your example is not equivalent, it is possible to get the same effect. Placing a conditional where the two branches are an empty list and a block of code at every place you mean next gets the job done.


In reply to Re: Re: "foreach" is to "next" as "map" is to ??? by Limbic~Region
in thread "foreach" is to "next" as "map" is to ??? by McMahon

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.