micromarch
asked on
perl scripting help
Hi. I have a script here but it is not doing what its suppose to do. I am trying to make it so it sorts my array ascending. Here is the script.
#!/usr/bin/perl
@array = (5,3,2,1,4);
$i=1;
$a=1;
$s=1;
var1=0;
var2=0;
var3=0;
var4=0;
var5=0;
while($i < $#array) {
for($j=0; $j < $#array; $j++){
if ($array[$j] == $a) {
$var[$s]=$a;
$a=$a+1;
$i=$i+1;
$s=$s+1;
}
}
}
@array = ($var1,$var2,$var3,$var4,$ var5);
foreach $elem (@array){
print "$elem";
}
#!/usr/bin/perl
@array = (5,3,2,1,4);
$i=1;
$a=1;
$s=1;
var1=0;
var2=0;
var3=0;
var4=0;
var5=0;
while($i < $#array) {
for($j=0; $j < $#array; $j++){
if ($array[$j] == $a) {
$var[$s]=$a;
$a=$a+1;
$i=$i+1;
$s=$s+1;
}
}
}
@array = ($var1,$var2,$var3,$var4,$
foreach $elem (@array){
print "$elem";
}
@array = sort{$a<=>$b} @array;
ASKER
i know this works, but im trying to do it the cheap way.
@array = sort{$a<=>$b} @array;
is the cheap way
is the cheap way
ASKER
well then the more complicated way as you can see with my code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.