Link to home
Start Free TrialLog in
Avatar of micromarch
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";
}


Avatar of ozo
ozo
Flag of United States of America image

@array = sort{$a<=>$b} @array;
Avatar of micromarch
micromarch

ASKER

i know this works, but im trying to do it the cheap way.
@array = sort{$a<=>$b} @array;
is the cheap way
well then the more complicated way as you can see with my code.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial