Re: help on example from "mastering algorithm with perl" on binary search

2009-06-27 Thread John W. Krahn
rich lee wrote: Hello everyone, Hello, I am trying to read "mastering algorithm with perl" and below example has me bit stuck. I understand everything except these 2 lines $low = $try + 1, next if $array->[$try] lt $word; $high = $try -1, next if $array->[$try] gt $w

help on example from "mastering algorithm with perl" on binary search

2009-06-27 Thread rich lee
Hello everyone, I am trying to read "mastering algorithm with perl" and below example has me bit stuck. I understand everything except these 2 lines $low = $try + 1, next if $array->[$try] lt $word; $high = $try -1, next if $array->[$try] gt $word; I understand what it's

Re: Perl comparison function for binary search

2008-04-13 Thread Nelson Castillo
On Sun, Apr 13, 2008 at 10:17 PM, John W. Krahn <[EMAIL PROTECTED]> wrote: > > Nelson Castillo wrote: (cut) > That won't work correctly unless the numbers are sorted correctly: > > $ perl -le' print for sort { $a cmp $b } 0, 2, 3, 11, 12' > 0 > 11 > 12 > 2 > 3 Hi. I wanted to stress that wi

Re: Perl comparison function for binary search

2008-04-13 Thread John W. Krahn
Nelson Castillo wrote: On Sun, Apr 13, 2008 at 3:10 PM, John W. Krahn <[EMAIL PROTECTED]> wrote: (cut) my $c = &$cmpf($arr->[$mid], $value); That is usually written as: my $c = $cmpf->($arr->[$mid], $value); Thanks Chas. and John for your feedback. I think I'm happy with this ve

Re: Perl comparison function for binary search

2008-04-13 Thread Nelson Castillo
On Sun, Apr 13, 2008 at 3:10 PM, John W. Krahn <[EMAIL PROTECTED]> wrote: (cut) > >my $c = &$cmpf($arr->[$mid], $value); > > > > That is usually written as: > > > my $c = $cmpf->($arr->[$mid], $value); Thanks Chas. and John for your feedback. I think I'm happy with this version: #!/us

Re: Perl comparison function for binary search

2008-04-13 Thread John W. Krahn
Nelson Castillo wrote: Hi :-) Hello, I wrote this binary search function. I wrote it so that I could pass a comparison function as the last parameter. But I have to write "sub" and I noticed that the built in sort function doesn't need it. So I have to write: sub {

Re: Perl comparison function for binary search

2008-04-13 Thread Chas. Owens
On Sun, Apr 13, 2008 at 2:38 PM, Nelson Castillo <[EMAIL PROTECTED]> wrote: > Hi :-) > > I wrote this binary search function. I wrote it so that I could pass > a comparison function as the last parameter. But I have to write > "sub" and I noticed that the built i

Perl comparison function for binary search

2008-04-13 Thread Nelson Castillo
Hi :-) I wrote this binary search function. I wrote it so that I could pass a comparison function as the last parameter. But I have to write "sub" and I noticed that the built in sort function doesn't need it. So I have to write: sub { shift <=> shift} instead of: {$a &

Re: Binary search

2007-05-10 Thread Jenda Krynicky
> Is there a perl built in function that search a value in sorted array? > Although I found such an algorithm in the cpan (Search::Binary), I > wonder if there is an efficient solution within the core perl. No, there is not. Because if you want to do that you should most probably be using a hash

Re: Binary search

2007-05-01 Thread Jeff Pang
2007/5/1, [EMAIL PROTECTED] <[EMAIL PROTECTED]>: Hi all, Is there a perl built in function that search a value in sorted array? Although I found such an algorithm in the cpan (Search::Binary), I wonder if there is an efficient solution within the core perl. For large array which was sorted a

Binary search

2007-05-01 Thread yaron
Hi all, Is there a perl built in function that search a value in sorted array? Although I found such an algorithm in the cpan (Search::Binary), I wonder if there is an efficient solution within the core perl. Thanks in advanced, Yaron Kahanovitch -- To unsubscribe, e-mail: [EMAIL PROTECTED] F