In pursuit of this issue .
How to simplify and optimize code for outputting a diamond to perl?
It works, but after javascript it seems somewhat ugly, especially the construction in $ out and the second condition while:
$i = 1; print "Введите размер стороны: "; chomp($side = <STDIN>); $prob = $side - $i; $stend = ' ' x $prob . '#' . "\n"; print $stend; $i++; while ($i <= $side) { $prob = $side - $i; $out = ' ' x $prob . '#' . ' ' x (($i *2) - 3) . '#'; print $out . "\n"; $i++; } $i--; while ($i > 2) { $i--; $prob = $side - $i; $out = ' ' x $prob . '#' . ' ' x (($i *2) - 3) . '#'; print $out . "\n"; } print $stend . "\n"; In the online interpreter: Link to code
UPD: in $ out confuses the calculation *2) - 3 )