in reply to Print series of numbers

Isn't it golf challenge? http://codegolf.com/home-on-the-range

Anyway, few hints:

Replies are listed 'Best First'.
Re^2: Print series of numbers
by GrandFather (Saint) on Oct 20, 2009 at 10:29 UTC

    sort uses cmp, not <=> (the spaceship operator) by default. Consider:

    my @list = (1, 2, 3, 6, 9, 10, 13, 22, 20, 19, 15, 21); printf "<=>: %s\n", join ",", sort { $a <=> $b } @list; printf "cmp: %s\n", join ",", sort { $a cmp $b } @list; printf " : %s\n", join ",", sort @list;

    Prints:

    <=>: 1,2,3,6,9,10,13,15,19,20,21,22 cmp: 1,10,13,15,19,2,20,21,22,3,6,9 : 1,10,13,15,19,2,20,21,22,3,6,9

    printf avoids the need to add a new line to the end of the parameter list after the join. In the OP's code printf seems to me to be more appropriate than print.

    Always use strictures (use strict; use warnings; - see The strictures, according to Seuss).


    True laziness is hard work
      Ups, you are right about sorting, corrected. And the rest depends on whether it is really golfing problem (print better) or normal task/job (I would discuss here if really printf is better in place where only new line 'must be achieved'. I prefer print with -l switch, but then of course the loop must be rewriten. And if it is perl 5.10, then we can even advice perlfunc-> say() without rewriting loop)
Re^2: Print series of numbers
by jethro (Monsignor) on Oct 20, 2009 at 10:40 UTC
    not ugly != golf
Re^2: Print series of numbers
by mickep76 (Beadle) on Oct 20, 2009 at 10:55 UTC

    Cool didn't know about this challenge, to bad the examples are not available for viewing that would have given me an endless number of solutions.