in reply to Terse Code for Odd Numbers

Basically same thing, just slightly different construct (half the iterations)
perl -le 'print map {$_*2+1} 1/2..13/2'
Update: Can just use 'for' instead of 'map'..
perl -le 'print 2*$_+1 for 1/2..13/2'

Replies are listed 'Best First'.
Re^2: Terse Code for Odd Numbers
by gaal (Parson) on May 13, 2005 at 20:29 UTC
    Perl6 version (doesn't work yet on current pugs):

    say (2 .. 13 :by(2))

Re^2: Terse Code for Odd Numbers
by mrborisguy (Hermit) on May 13, 2005 at 20:21 UTC
    wait a second...

    1/2 * 2 + 1
    = 2/2 + 1
    = 1 + 1
    = 2

    isn't that an even number?
    i think you meant:
    perl -le 'print map {$_*2+1} 0..12/2
    Update:
    Nope, i was wrong. i started thinking about how to do this given a low and a high, so i got about this far: int( $low/2 )..int( $high/2 ) when i realized, hey, the .. operator probably takes the int of the values already. so i tried it, and after running the code provided, i found out the .. operator already does take the int of the values, so your answer works. sorry.