andreas1234567 has asked for the wisdom of the Perl Monks concerning the following question:
How do I get rid of the extra newlines in the output?
Actual output:use strict; use warnings; use String::CamelCase qw(decamelize); use PPI::Tokenizer; my @lines = <DATA>; my $tokenizer = PPI::Tokenizer->new(\@lines); while (my $token = $tokenizer->get_token) { no warnings q{uninitialized}; my $no_decam = 0; ++$no_decam if $token =~ m/^\s*$/; # skip whitespace ++$no_decam if $token =~ m/^__\w+__$/; # skip packages ++$no_decam if $token =~ m/::/; # skip modules ++$no_decam if $token =~ m/^['"].*['"]$/; # skip quoted strings ($no_decam) ? print $token : print decamelize($token); } 1; __DATA__ sub new { my $Class = shift; my $Self = {}; bless($Self, $Class); $Self->{FooBar} = Foo::Bar->new(base => __PACKAGE__); if (!$Self->{FooBar}) { croak("Foo::Bar init failed!"); } return $Self; }
Wanted output:sub new { my $class = shift; my $self = {}; bless($self, $class); $self->{foo_bar} = Foo::Bar->new(base => __PACKAGE__); if (!$self->{foo_bar}) { croak("Foo::Bar init failed!"); } return $self; }
sub new { my $class = shift; my $self = {}; bless($self, $class); $self->{foo_bar} = Foo::Bar->new(base => __PACKAGE__); if (!$self->{foo_bar}) { croak("Foo::Bar init failed!"); } return $self; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Preserve whitespace with PPI::Tokenizer
by ikegami (Patriarch) on Feb 27, 2009 at 14:24 UTC |