in reply to Minimum width in printf() ignored?

Are you sure the code you posted is exactly the same as the code you are running? And that your script is actually executing the sprintf you exhibited?

My attempt at a SSCE is

my $last_n = 'E6/11/C#';
my $n      = 'E6/11/Db';
sub notenames { return 'unknown' }
print "Perl $^V\n";

      my $out = sprintf("Two names: '%-16s', '%-16s' for ", $last_n, $n);
      print $out . "        " . &notenames($k) . "\n";

with the indented lines cut-and-pasted from your post. I have run this under Perls 5.40.0 and 5.10.1 and gotten

Perl v5.40.0
Two names: 'E6/11/C#        ', 'E6/11/Db        ' for         unknown

and

Perl v5.10.1
Two names: 'E6/11/C#        ', 'E6/11/Db        ' for         unknown

respectively.

Replies are listed 'Best First'.
Re^2: Minimum width in printf() ignored?
by Miq19 (Novice) on Sep 01, 2024 at 16:01 UTC
    Found it! The file is binary, so there are binary zero bytes behind the texts when I extract these. I did not think about that and used
    (@c) = $block =~ /(\d{14})(\d\d)(.*)/;
    to extract the contents. Thus the zero bytes were kept as part of $c3. Instead I should have used
    (@c) = $block =~ /(\d{14})(\d\d)([ -z]*)/;
    This now yields
    Two names: 'F#maj13/Eb ', 'Gbmaj13/Eb ' for D#/Eb4, +F#/Gb4, A#/Bb4, F5,
    as I intended it. Thank any way for your help, it pushed me in the right direction!

      Ah-hah! You figured out what we were assuming, that was not in fact true. Good hunting!