Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching for a variable in a regular expression

Status
Not open for further replies.

cb49747

MIS
Apr 23, 2002
181
0
0
US
Here is the problem. I have various queries stored which grab different information from the database. Associated with each query is some text. This text is different for each query. In this text is information that tell which fields to show and where.

an example of this text would be

$text = "please show this field [[showfield4]] and then show this field [[showfield5]]";

When the query runs say it finds 10 matches. the info in these fields is different for each match.

What I want to do is do a regular expression that will search this text and replace the [[showfield3]] with $alert[3]

This is what I currently have but doesn't work.

while (@alert = $run_ealert->fetchrow_array) {
$temp_text = $ealert_text;
for ($c = 0; $c <= $#alert; $c++) {
$temp_text =~ s/[[showfield$c]]/$alert[$c]/g;
print $temp_text;

I'm not getting a match.

Any help would be greatly appreciated.

Thanks in advance.
 
ok,

now I'm really confused. Is my above code that bad? or are you guys just giving me a hard time. Again here is the completed code.

Code:
$run_ealert = $dbh->prepare( $ealert_query );
 $run_ealert->execute();
  $total_emails = 0;
   while (@alert = $run_ealert->fetchrow_array) {	  
    $total_emails ++;
    my $temp_text = $ealert_text;
    for ($c = 0; $c <= $#alert; $c++) { $temp_text =~ s/ShowField${c}/$alert[$c]/g; }
    SendEalert($alert[1],$temp_text,$alert[2]);	  
   }

Again help in making this more efficient would be greatly appreciated.
 
Code:
$run_ealert = $dbh->prepare( $ealert_query );
$run_ealert->execute();
$total_emails = 0;
while (@alert = $run_ealert->fetchrow_array) {      
  $total_emails ++;
  $ealert_text=~s/ShowField(\d+)/$alert[$1]/g;
  SendEalert($alert[1],$ealert_text,$alert[2]);      
}

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Thats basically the code I posted earlier in the thread. Then they said they were using the wrong variable all along. Hence the head and hammer.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top