You can also look for the =~ operator and then print the next significant token:
#!/usr/bin/perl use strict; use PPI; # warnings should always go last # https://stackoverflow.com/a/38639882/78259 use warnings; my $file = shift or die "Need a file name!\n"; my $document = PPI::Document->new( $file ); my $tokens = $document->find( sub { my ($self, $token) = @_; $token->isa('PPI::Token::Regexp') or $token->isa('PPI::Token::Operator'); } ) || []; print "\n$file :\n"; for my $token ( @$tokens ) { if ($token->isa("PPI::Token::Regexp")) { print "\t", $token->content, "\n"; next; } next unless $token->content eq "=~"; my $next_token = $token->snext_sibling; next if $next_token->content =~ m{^(?:[ms].|/)}; print "\t", $next_token->content, " at line ", $next_token->location->[3], "\n"; } On Tue, Jun 13, 2017 at 10:47 AM Lars Noodén <lars.noo...@gmail.com> wrote: > On 06/13/2017 05:14 PM, Chas. Owens wrote: > > Two notes: > > > > Firstly, $document->find will return undef if no regexes are found, not > an > > empty arrayref, so you should say > [snip] > > > Secondly, PPI does not catch all things that can be considered regexes, > for > > instance: > [snip] > > Thanks. I appreciate the observations. On that second one, I figure it > is all but impossible to catch some cases and am simply hoping that they > are not going to be in the code base I scan. I will try some other > searches on the side to see if something like this shows up: > > m/ =~ \s+ \$\w+ \s+ \? /x > > Regards > Lars > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >