in reply to Re: Find the biggest number from three numbers
in thread Find the biggest number from three numbers

It looks astonishing to me that there are so many ways to solve a single problem. I haven't understood your example at full now, but I will eventually. I have only learned if, elsif and else and how they work. :-D I won't be asking here what this and that is.The next things I will be searching: And I will start studying the Learning perl book which a friend of mine has directed. This is my first ever program(except from hello world and similar programs from net)
  • Comment on Re^2: Find the biggest number from three numbers

Replies are listed 'Best First'.
Re^3: Find the biggest number from three numbers
by oko1 (Deacon) on Dec 26, 2010 at 02:56 UTC

    Heh. The motto of Perl is 'TMTOWTDI' - "There's More Than One Way To Do It". If you had asked to see different ways that people could implement that problem, you would have seen an amazing variety of ways to do it; in my experience, our fellow monks here are endlessly inventive. Here's a somewhat amusing one, off the top of my head:

    #!/usr/bin/perl -l use warnings; use strict; my @x; print "Please enter one number per line (empty line ends input):"; while (<STDIN>){ last if /^$/; push @x, $_; } print "The biggest number is ", (sort {$b<=>$a} @x)[0], "@x" =~ /^([-0-9]+)\s+(?:\1\s+)*$/ && "All numbers are the same";

    (Now don't let that distract you. "Learning Perl" is an excellent start for a Perl novice, so go study. :)


    -- 
    Education is not the filling of a pail, but the lighting of a fire.
     -- W. B. Yeats
    
Re^3: Find the biggest number from three numbers
by ysth (Canon) on Dec 26, 2010 at 07:42 UTC
    $biggest = ($a+$c+$b+$c+abs($a-$b)+abs($c-$a+$c-$b-abs($a-$b)))/4;
    --
    A math joke: r = | |csc(θ)|+|sec(θ)|-||csc(θ)|-|sec(θ)|| |
    Online Fortune Cookie Search
Re^3: Find the biggest number from three numbers
by Tux (Canon) on Dec 26, 2010 at 09:23 UTC

    Don't use $a and $b :)

    use List::Util qw( max ); ($a, $b, $c) = (3, 12, 42); print +(sort { $b <=> $a } $a, $b, $c)[0]; print max ($a, $b, $c);

    These both work, but can you - as a perl beginner - still read it? Perl is so much fun due to TIMTOWTDI


    Enjoy, Have FUN! H.Merijn