Thread suche in einem array (20 answers)
Opened by bo at 2006-12-21 12:12

PerlProfi
 2006-12-21 12:18
#72663 #72663
User since
2006-11-29
340 Artikel
BenutzerIn
[default_avatar]
Du brauchst die for-Schleife da gar nicht:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
use strict;
use warnings;

my @ids = (1, 3, 4, 12, 41, 43, 44);
my $id = 4;
my $prev_id = defined($ids[$id-1]) ? $ids[$id-1] : 'undef';
my $next_id = defined($ids[$id+1]) ? $ids[$id+1] : 'undef';

print qq(ID: $id => NEXT: $next_id => PREV: $prev_id\n);


MfG PerlProfi

View full thread suche in einem array