To print a hollow inverted pyramid pattern in Perl, we use nested loops to manage spaces and stars.
In this example,
#!/usr/bin/perl
use strict;
use warnings;
my $num_rows = 5;
for my $row (reverse(1..$num_rows)) {
my $pattern = '';
$pattern .= ' ' x ($num_rows - $row);
if ($row == $num_rows || $row == 1) {
$pattern .= '*' x (2 * $row - 1);
} else {
$pattern .= '*';
$pattern .= ' ' x (2 * $row - 3);
$pattern .= '*';
}
print "$pattern\n";
}
********* * * * * * * *
In this tutorial, we learned How to print Hollow Inverted Pyramid Pattern in Perl language with well detailed examples.