Print stars like a Triangle in Perl

Perl Script to code to print stars like a Triangle

Source code :

$i,$sp,$k=0;

for($i=1;$i<=5;$i=$i+1){
    
    for($sp=1;$sp<=5-$i;$sp=$sp+1){
       print"  ";
    }
    
    while($k!=2*$i-1){
       print"* ";
       $k=$k+1;
    }
    
$k=0;
print"
";
}

Output :

        
        
        
        
        * 

Output :


                

Comments :