in reply to general advice finding duplicate code
use strict; use warnings; use 5.010; my $fname = 'somefile.php'; #Slurp whole file: my $file; { local $/ = undef; $file = <DATA>; } my %files_for; while($file =~ m{ <[?]php \s* (.*?) \s* [?]> }xmsg) { my $php_code = $1; push @{ $files_for{$php_code} }, $fname; } use Data::Dumper; say Dumper(\%files_for); __END__ <div>hello</div> <div><?php echo 'world'; ?> <div><?php echo 'hello';?> <div><?php echo 'world';?> --output:-- $VAR1 = { 'echo \'world\';' => [ 'somefile.php', 'somefile.php' ], 'echo \'hello\';' => [ 'somefile.php' ] };
|
|---|