sub print_multiple {
my ($count, $string, $format) = @_;
for (1..$count) {
print &format_string ($string, $format), "\n";
}
return;
}
sub format_string {
my ($string, $format) = @_;
my %templates = (
'bold' => '%s',
'italic' => '%s',
);
return (sprintf ($templates{$format}, $string));
}
&print_multiple (5, 'hello, world.', 'bold');
####
sub print_multiple {
my $b = shift;
for (1..$b->{'count'}) {
print &format_string ($b), "\n";
}
return;
}
sub format_string {
my $b = shift;
my %templates = (
'bold' => '%s',
'italic' => '%s',
);
return (
sprintf (
$templates{ $b->{'format'} },
$b->{'string'}
)
);
}
$block = {
'string' => "hello, world.",
'format' => "bold",
'count' => 5,
};
&print_multiple ($block);