U
usenet
Suppose I have an array like this:
my @array = ('foo', '', 'bar', '', '', '', 'baz', '');
and I want to find the index value of the third undefined element. I
can do something really ugly like this:
my $search_for = 3; #find index of third undefined element
my $undefined = 0;
foreach my $index(0..$#array) {
$undefined++ unless $array[$index];
if ($undefined == $search_for) {
print "Index of undefined element #$search_for is $index\n";
next;
}
}
but I HATE THAT CODE. It's ugly. It's inelegant. It's an offense to
human dignity. It increases global warming. Is there a better (and
more environmentally safe) technique?
my @array = ('foo', '', 'bar', '', '', '', 'baz', '');
and I want to find the index value of the third undefined element. I
can do something really ugly like this:
my $search_for = 3; #find index of third undefined element
my $undefined = 0;
foreach my $index(0..$#array) {
$undefined++ unless $array[$index];
if ($undefined == $search_for) {
print "Index of undefined element #$search_for is $index\n";
next;
}
}
but I HATE THAT CODE. It's ugly. It's inelegant. It's an offense to
human dignity. It increases global warming. Is there a better (and
more environmentally safe) technique?