in reply to sprintf problem
#!/usr/bin/perl use strict; use warnings; my $spaces=0; while (chomp(my $line=<DATA>)) { $line =~ s/^\s+|\s+$//g; if ($line =~ /}/) { $spaces-=4; } my $padded = ' ' x $spaces . $line; print "$spaces:$padded\n"; if ($line =~ /{/) { $spaces+=4; } }
avoiding the sprintf all together. More info at sprintf - search for "(minimum) width".
|
|---|