Two notes:
Firstly, $document->find will return undef if no regexes are found, not an
empty arrayref, so you should say
my $regex = $document->find('PPI::Token::Regexp') || [];
or
for my $expr ( @[ $regex || [] ] ) {
or even
print qq(\n$file :\n);
if (my $regex = $document->find('PPI::Token::Regexp')) {
for my $expr ( @$regex ) {
print qq(\t),$expr->content,qq(\n);
}
} else {
print "\tno matches\n";
}
Whatever makes the most sense to you.
Secondly, PPI does not catch all things that can be considered regexes, for
instance:
#!/usr/bin/perl
use strict;
use warnings;
my $regex = "foo";
print "foo" =~ $regex ? "matched" : "no match", "\n";
This is perfectly valid Perl 5 code, but PPI won't recognize it as
containing a regex.
On Tue, Jun 13, 2017 at 8:49 AM Lars Noodén <[email protected]> wrote:
> Ok. Thanks, Paul and David.
>
> I think I see how I can benefit from Text::Balanced but I now have my
> start with PPI and can list the expressions.
>
> Regards,
> Lars
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use PPI;
> use Data::Dumper;
>
> my $file = shift or ( die("Need a file name!\n") );
>
> my $document = PPI::Document->new( $file );
>
> my $regex = $document->find('PPI::Token::Regexp');
>
> # print Data::Dumper->Dump($regex),qq(\n);
>
> print qq(\n$file :\n);
>
> for my $expr ( @$regex ) {
> print qq(\t),$expr->content,qq(\n);
> }
>
> exit( 0 );
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>