Re: Continous Looping of a List
From: Paul Lalli (mritty_at_gmail.com)
Date: 09/25/04
- Next message: Paul Lalli: "Re: Continous Looping of a List"
- Previous message: krakle: "Re: Help with my brute force method"
- In reply to: cp: "Re: Continous Looping of a List"
- Next in thread: cp: "Re: Continous Looping of a List"
- Reply: cp: "Re: Continous Looping of a List"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 24 Sep 2004 19:41:43 -0400
cp wrote:
> My very bad. In my original problem statement, I neglected to mention
> that I need the loop to be continuous. So if the current selected id is
> 9, the functions needs to return 7 and 1. If the current selection is
> 1, it needs to return 9 and 3.
>
The output of my function is identical to the output of your funciton,
including returning the 2nd and last element when given the first. Can
you explain to me what your function does that mine does not?
Did you try to run my function, or are you just making an assumption it
doesn't do what you want?
> In article <KW_4d.173$va.125@trndny03>, Paul Lalli <mritty@gmail.com>
> wrote:
>
>>My version of your function:
>>
>>sub array_nav {
>> my ($val, @ids) = @_;
>> my $pos;
>> for ($pos=0; $pos<=$#ids; $pos++){
>> last if $val == $ids[$pos];
>> }
>> return undef unless $pos < @ids; #error checking
>
>
> Yes. I see what you are doing. however, I was hoping for error checking
> to determine whether the selected id was part of the set Before
> looping. May fault for not stating the problem more clearly.
>
The question here is "why?" Assuming you do have some sort of valid
reason for this, checkout the Perl FAQ:
perldoc -q contained
>
>> my $prev = $ids[$pos-1];
>> my $next = $pos == $#ids ? $ids[0] : $ids[$pos+1];
>> return ($prev, $next);
>>}
Paul Lalli
- Next message: Paul Lalli: "Re: Continous Looping of a List"
- Previous message: krakle: "Re: Help with my brute force method"
- In reply to: cp: "Re: Continous Looping of a List"
- Next in thread: cp: "Re: Continous Looping of a List"
- Reply: cp: "Re: Continous Looping of a List"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|