Best practice question
Posted
by sid_com
on Stack Overflow
See other posts from Stack Overflow
or by sid_com
Published on 2010-03-21T07:58:35Z
Indexed on
2010/03/21
12:01 UTC
Read the original article
Hit count: 192
Hello! Which version would you prefer?
#!/usr/bin/env perl
use warnings;
use strict;
use 5.010;
my $p = 7; # 33
my $prompt = ' : ';
my $key = 'very important text';
my $value = 'Hello, World!';
my $length = length $key . $prompt;
$p -= $length;
Option 1:
$key = $key . ' ' x $p . $prompt;
Option 2:
if ( $p > 0 ) {
$key = $key . ' ' x $p . $prompt;
}
else {
$key = $key . $prompt;
}
say "$key$value"
© Stack Overflow or respective owner