Phillip wrote:
Hallo @ all,
Hello,
i am new in this domain(perlscript) and i have a question.i have a
array,i sort it,i get the last element of the array but i want to get
the next element after this one.how can i do this?
for example:
$arr1=("6,3,8,1") --->>my last element is 1 and mark that is the last
element
now i sort them ---->> $arr1=("1,3,6,8")
my last element is 1 and now i want to go to the next element in the
list,how can i do this?
if i do something like this:$next=$last+1; --->>in this case $next will
be 2 and this is not my third element in my list,i want the 3.
BR,
Phil
here is my code:
@arr[1]=("3,7,13,1,19,5,9");
@array=split(/,/,@arr[1]);
That should be:
my @array = ( 3, 7, 13, 1, 19, 5, 9 );
$i=0;
while(@array[$i])
{
$i=$i+1;
}
print"Anzahl:$i\n";
print "Anzahl:", scalar @array, "\n";
@sorty=sort(Nummernsort @array);
sub Nummernsort{
if($a<$b){
return -1;
}elsif($a==$b){
return 0;
}else{
return 1;
}
}
my @sorty = sort Nummernsort @array;
sub Nummernsort { $a <=> $b }
print "sort:@sorty\n";
$last=$array[$i-1];
my $last = $array[ -1 ];
print "last:$last\n";
$next=?
Do you want the next-to-last?
my $next = $array[ -2 ];
print"nextt=$next\n";
John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/