sprintf('%-50s%s', $key, $value)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/usr/bin/perl/ use strict; use warnings; use 5.010; my $key = 'foo'; my $value = 'bar'; my $str = sprintf('%-50s%s', $key, $value); say $str; my ($k, $v) = (substr($str, 0, 50), substr($str, 50)); say "'$k'"; say "'$v'"; die "wrong pattern: $str" if ($k !~ s/\s+$// or $v =~ /^\s+/); say "'$k'"; say "'$v'";
if ($str =~ /^(\w+\s+){50}\w+$/)
1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/perl/ use strict; use warnings; my $key = 'foo'; my $value = 'bar'; my $str = sprintf('%-50s%s', $key, $value); die "wrong pattern: $str" unless $str =~ /^\w+\s+(\w+)$/ and $-[1]==50;
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/bin/perl/ use strict; use warnings; my $key = 'foo'; my $value = 'bar'; my $str = sprintf('%-50s%s', $key, $value); my $l = length($str)-50; die "wrong pattern: $str" unless $str =~ /^\w+\s+\w{$l}$/;
QuoteAlso der Key 50-stellig mit Leerzeichen nach Rechts aufgefüllt.