walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; my $spaces=0; while (chomp(my $line=<>)) { $line =~ s/^\s+|\s+$//g; if ($line =~ /}/) { $spaces-=4; } my $padded = sprintf("%${spaces}s",$line); print "$spaces:$padded\n"; if ($line =~ /{/) { $spaces+=4; } }
#!/usr/bin/perl my $blah=1; my $blah2=3; if ($blah1 =~ blah2) { then do this; and if not { then do this as well; and then this { blah; } return it; } talk }
0:#!/usr/bin/perl 0: 0:my $blah=1; 0:my $blah2=3; 0: 0:if ($blah1 =~ blah2) { 4:then do this; 4:and if not { 8:then do this as well; 8:and then this { 12: blah; 8: } 8:return it; 4: } 4:talk 0:}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sprintf problem
by kennethk (Abbot) on Aug 19, 2009 at 18:59 UTC | |
|
Re: sprintf problem
by jrsimmon (Hermit) on Aug 19, 2009 at 18:51 UTC | |
|
Re: sprintf problem
by ikegami (Patriarch) on Aug 19, 2009 at 18:59 UTC | |
|
Re: sprintf problem
by biohisham (Priest) on Aug 20, 2009 at 00:29 UTC |