I 've never done perl in my life and a few regex. But i need to debug a perl file that read function reference that could be on multiple line. Indeed I got this type of regex :
my @m = ($content =~ /.*\s*function\s*\((\w+)\s*\,\s*(\w+)\s*\)\;.*/ig)
where $content
is my multiple line string (in fact a file content). But I don't understand why I only match pattern like this
function(param1,param2);
And I don't match if there is a line break after the comma. The following function isn't recognized.
function(param1,
param2);
My Code is like that:
open (FILE, "myfile") or die "Trouble opening the file";
my $content;
local $/;
$content=<FILE>;
my @m;
@m = ($content =~ /\s*function\s*\((\w+)\s*,\s*(\w+)\s*\)\;/gi);
foreach (@m) {
print "$_\n";
}
BTW sorry for my poor english.
As said in comments, remove .*
, you may also remove the unnecessary escapes:
use Modern::Perl;
use Data::Dumper;
my $content = <<EOD;
function(param11,param12);
function(param21,
param22);
function
(param31
,
param32
);
EOD
my @m = ($content =~ /function\s*\((\w+)\s*,\s*(\w+)\s*\);/ig);
say Dumper\@m;
Output:
$VAR1 = [
'param11',
'param12',
'param21',
'param22',
'param31',
'param32'
];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.