Re: [solved] Re: Module to extract patterns

2017-06-13 Thread Chas. Owens
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(

Re: [solved] Re: Module to extract patterns

2017-06-13 Thread Lars Noodén
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

Re: [solved] Re: Module to extract patterns

2017-06-13 Thread Chas. Owens
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 =

[solved] Re: Module to extract patterns

2017-06-13 Thread Lars Noodén
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 =

Re: Module to extract patterns

2017-06-13 Thread David Mertens
See also Text::Balanced and its extract_quotelike: http://search.cpan.org/~shay/Text-Balanced-2.03/lib/Text/Balanced.pm#extract_quotelike David On Tue, Jun 13, 2017 at 7:23 AM, Paul Johnson wrote: > On Tue, Jun 13, 2017 at 02:03:10PM +0300, Lars Noodén wrote: > > There are a

Re: Module to extract patterns

2017-06-13 Thread Paul Johnson
On Tue, Jun 13, 2017 at 02:03:10PM +0300, Lars Noodén wrote: > There are a lot of ways to write patterns. > Is there a module or method that can identify and extract them from a > larger bit of code regardless of style? That's not an easy problem. Fortunately, there is a module which will

Module to extract patterns

2017-06-13 Thread Lars Noodén
There are a lot of ways to write patterns. /foo/; m/foo/; m|foo|; m| foo |x; m/foo\//; qr/foo/; qr|foo|; qr/ foo /x; s/foo/bar/; s/ foo /bar/x; s| foo |bar|x; and so on. Is there a module or method that can identify and extract them from a larger bit of code regardless of style?