Well, you don't need it in that situation:
$$file =~ s/<%[ ]*link_name[ ]*([^ ]*)[ ]*%>(?{push(@link_names,$1);})/<% link_n +ame $1%>/g; #can be rewritten as (changed single space to \s, might # be more usefull $$file =~ s{ <% \s* link_name \s* (\S*) \s* %> }{ push @link_names,$1; "<% link_name $1 %>" }xg; # but in fact you don't even need s/// while($$file =~ m{ <% \s* link_name \s* (\S*) \s* %> }xg ){ push @link_names,$1 }
It looks like you first look for each link in the template, then you fetch _each_ number from the database and replace each number again. I'd recommand you either use s///e and put a function-call into the replacement, where the function fetches the database information and returns the link or HTML comment for errors, or you do your search first, but keep in mind the positions of your links, so you'll find'em much faster. The second method has the great advantage that you can fetch all link-information at once.
--while($$file =~ m{( <% \s* link_name \s* (\S*) \s* %> )}xg ){ push @link_names,[pos($$file)-length($1),length($1),$2] } #now fetch stuff from database at once if(@link_names){ my $sql = 'SELECT template_id from template_table where '. join(' OR ',(('template_name = ?')x @link_names)); #... you're hopefully using DBI $sth->execute( @link_names ); #... #replacement can be done easily and _fast_ because # you know the positions of your links and their # length, so use substr(!) here }
In reply to Re: Is it safe to use code evaluation regexp or will it be deprecated
by fruiture
in thread Is it safe to use code evaluation regexp or will it be deprecated
by Rodney_Hampton
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |