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 }
--
http://fruiture.de

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.