I could be misunderstanding, but if I'm reading you right, the code is something like this:
use strict; my $Kine = "Hello, FLF12. Would you like to play FLF22?"; # I've substituted array refs for the SQL query. It's # approximately the same as the 'while' line you have. foreach my $row (["Dr. Falken", "a game"], ["Bobby Fischer", "some che +ss"]) { my @Replacement = (); $Replacement[12]=$row->[0]; $Replacement[22]=$row->[1]; $Kine=~s/FLF(\d\d)/$Replacement[$1]/ge; print $Kine, "\n"; }
Here's my guess (and it's just a guess) as to what's going on: you're doing a substitution for each row that you pull out of the database. First row, everything substitutes fine, so $Kine is 'Hello, Dr. Falken. Would you like to play a game?' Then we get to the second row. The regexp scans $Kine again, but this time it contains no tags. In fact, it contains 'Hello, Dr. Falken. Would you like to play a game?' still. So there are no tags for it to replace, and so it prints out 'Hello, Dr. Falken. Would you like to play a game?' again.

Instead, try this:

use strict; my $Kine = "Hello, FLF12. Would you like to play FLF22?"; foreach my $row (["Dr. Falken", "a game"], ["Bobby Fischer", "some che +ss"]) { my @Replacement = (); $Replacement[12]=$row->[0]; $Replacement[22]=$row->[1]; # Copy $Kine into temporary variable my $out = $Kine; $out =~ s/FLF(\d\d)/$Replacement[$1]/ge; print $out, "\n"; }
Which prints out:
Hello, Dr. Falken. Would you like to play a game? Hello, Bobby Fischer. Would you like to play some chess?

stephen


In reply to Re: Perl SQL substitution pain! by stephen
in thread Perl SQL substitution pain! by catcher

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.