[kamloops-pm] Hello

Anthonyj anthonyj at jonathan.abda.net
Thu Oct 9 13:28:46 CDT 2003


Well, here's one to discuss.  I'm still fairly new to perl, and I ran into
an odd problem.

I haven't seen this in any other script, but it's happening here.  When
printed or returned, the variable, $post_data appears to contain nothing,
but when I move the print statement (commented at the moment) or the return
statement up a few lines, and inside the loop, they will work there, making
it appear as if, the scope of the variable is limited to the loop, and that
outside the loop it has no value.

Doesn't make sense, but it works when I make that change.  I have this code
working with that one modification, but I'm really puzzled on the theory
end.  If anyone has any guesses or can enlighten me on why this might
happen, I'd love to hear your thoughts.

Jonathan (here's the code in question)

All this function is doing is gather data from mysql, then processing an
html file and filling it with the values we've grabbed from mysql, and
$post_data is what is to be returned, holding all that html.  (constants in
the select statement are intended to be static for the moment, just for
current testing)

sub display_goal_posts
{

#get discussion for current goal
our ($sth, $SQL);

$SQL="SELECT * FROM goal_posts WHERE Project = '1' and Goal = '2'";
$sth=getRS($SQL, $dbh);

my %goal_posts;
while (my $row = $sth->fetchrow_hashref() )
{
$goal_posts{ID} = $row->{ID};
$goal_posts{Goal} = $row->{Goal};
$goal_posts{Text} = $row->{Text};

open (HTML,"<" . $goal_post) or  print "Cannot open $goal_post\n";
my @table_template = <HTML>;
close (HTML);

my %replace;
$replace{POST_TEXT} = $goal_posts{Text};

my $post_data .= join("\n", @table_template);
$post_data =~ s|<!--%(.*?)%-->|$replace{$1}|gs;
}

#print $post_data;
return $post_data;

}

________________________________________________
MailServer powered by
SilverServers Inc.
Visit us at http://www.SilverServers.com



More information about the kamloops-pm mailing list