Re: obj 8-2

Discussion in 'Perl Misc' started by John Black, Feb 22, 2014.

  1. John Black

    John Black Guest

    In article <>, id says...
    >
    > On Fri, 21 Feb 2014 14:46:33 -0600, Marek Novotny wrote:
    >
    > > On Fri, 21 Feb 2014 22:36:20 +0200, George Mpouras wrote:
    > >
    > >> how about finding the answer without IF ?
    > >>
    > >>
    > >> my @array = qw(42 41 42 31 54 420 56 57 46 58 59 60 34 61);
    > >> my $max = $array[0];
    > >> $max = (($_ + $max)/2) + (abs($_ - $max)/2) foreach @array[1 ..
    > >> $#array];
    > >> print $max

    > >
    > > A requirement for the lesson was to use loops and if.

    >
    >
    > OK.
    >
    > my @array = qw(42 41 42 31 54 420 56 57 46 58 59 60 34 61);
    >
    > sub max {
    > local $_ = shift;
    > return $_ unless @_;
    > if ($_ > $_[0]) {
    > shift;
    > unshift $_;
    > }
    > goto &max
    > }
    >
    > print $max for (1);
    >
    > See, a loop and an if. :)
    >
    > M4


    LOL. He's kidding Marek (even though I'm sure it works).

    John Black
    John Black, Feb 22, 2014
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Kamoski
    Replies:
    3
    Views:
    15,632
    Jay B. Harlow [MVP - Outlook]
    Aug 9, 2003
  2. Phil Endecott

    Obj* ptr = new Obj(X)

    Phil Endecott, Jun 3, 2005, in forum: C++
    Replies:
    5
    Views:
    449
    Mark P
    Jun 3, 2005
  3. Shalabh Chaturvedi
    Replies:
    2
    Views:
    428
    Mike C. Fletcher
    Feb 20, 2004
  4. Matthew Thorley

    How do you convert a string obj to a file obj?

    Matthew Thorley, May 4, 2005, in forum: Python
    Replies:
    7
    Views:
    483
    Peter Otten
    May 4, 2005
  5. alf
    Replies:
    9
    Views:
    388
Loading...

Share This Page