You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Andy Lim <an...@caltan.com> on 2001/04/04 19:34:26 UTC

A newbie question. -

I've been encountered with the "famous" random undefined sub error.
I learned how to fix this error when I call a sub functions from other
library files but, look at below test page.
I am having problem in calling subfunctions(AddNumber) defined in the same
HTML page.
The weired thing is, if I define this sub function at the top of this HTML
page, it generates no error at all. It means I get into trouble when I
define sub-functions at the bottom of each web pages.
I also tried embperl's meta command to define this sub function and called
it using "Execute" but I got still same error.

What am I doing wrong?


----- test.html ------------------
[$var $g_total $num3 $rrr $]

<html>
<head>
<title>test</title>
</head>
<body>
<H1>TEST of AddNumber</H1>
[-
	my $num = 5;
	my $num2 = 11;
	$num3 = 10;

	$g_total = AddNumber($num, $num2);
-]
<br>The total is [+ $g_total +].
</body>
</html>

[!
sub AddNumber
{
	my ($a, $b) = @_;
	my $total = $a+$b+$num3+5;

	return ($total);
}
!]

+++++++++++++++++++++++++++++++++
Andrew Lim
Web Developer
California Tan, Inc.
10877 Wilshire Blvd. 12th FL.
Los Angeles, CA 90024
T. 310.824.2508 ext.245
F. 310.824.0082


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


RE: A newbie question. -

Posted by Erik Arneson <ea...@musiciansfriend.com>.
On 04 April 2001, Andy Lim <an...@caltan.com> wrote:
> I wonder how other embperl users define subfunctions in the same HTML page
> or Are they all define sub functions in other files????

I tend to just use the Embperl pages for displaying the results of
things done in separate modules, most of the time.

So I guess you could say I keep all of my subroutines in other files.
:)

-- 
# Erik Arneson <ea...@musiciansfriend.com>   Web Engineer #
#  Mobile: 541.840.3100           GPG Key ID: 1024D/0A2C3C5E #
#  Office: 541.774.5391    <http://www.musiciansfriend.com/> #


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: A newbie question. -

Posted by Andre Landwehr <an...@gmx.net>.
On Wed, Apr 04, 2001 at 11:35:58AM -0700, Andy Lim wrote:
> Yeah, I think I shouldn't put my sub-functions at the bottom.
> Oh, there IS another solution.
> Using [* *] instead [- -] or [! !] solves this problem.

There are indeed some issues with [* *] which will be solved in
Embperl 2. I managed to build a fairly large website using
only [* *] already, but you have to be careful with it. For
example it does not re-initialize all variables when you reload
the page and other stuff like that.

> I wonder how other embperl users define subfunctions in the same HTML page
> or Are they all define sub functions in other files????

I do the latter most of the time also because it just works...
for the very rare cases I really need the sub inside the same
file I write it at the top.

Andre

--
 /"\
 \ /
  X  ASCII Ribbon campaign against HTML E-Mail
 / \


RE: A newbie question. -

Posted by Andy Lim <an...@caltan.com>.
Thank you Andre.

Yeah, I think I shouldn't put my sub-functions at the bottom.
Oh, there IS another solution.
Using [* *] instead [- -] or [! !] solves this problem.
But I am somewhat reluctant to use this because they says it's experimental
and they didn't say to use it to define functions anywhere from the embperl
docs.

I wonder how other embperl users define subfunctions in the same HTML page
or Are they all define sub functions in other files????

Andy


-----Original Message-----
From: Andre Landwehr [mailto:andre.landwehr@gmx.net]
Sent: Wednesday, April 04, 2001 11:27 AM
To: embperl@perl.apache.org
Subject: Re: A newbie question. -


On Wed, Apr 04, 2001 at 10:34:26AM -0700, Andy Lim wrote:
> The weired thing is, if I define this sub function at the top of this HTML
> page, it generates no error at all. It means I get into trouble when I
> define sub-functions at the bottom of each web pages.
> I also tried embperl's meta command to define this sub function and called
> it using "Execute" but I got still same error.
>
> What am I doing wrong?

I suppose it has something to do with your [- -] and [! !]
sections living in a different scope. I can confirm the behaviour
but I could'nt find any other solution than putting the function
at the top of the page either.

Andre

--
 /"\
 \ /
  X  ASCII Ribbon campaign against HTML E-Mail
 / \



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: A newbie question. -

Posted by Andre Landwehr <an...@gmx.net>.
On Wed, Apr 04, 2001 at 10:34:26AM -0700, Andy Lim wrote:
> The weired thing is, if I define this sub function at the top of this HTML
> page, it generates no error at all. It means I get into trouble when I
> define sub-functions at the bottom of each web pages.
> I also tried embperl's meta command to define this sub function and called
> it using "Execute" but I got still same error.
> 
> What am I doing wrong?

I suppose it has something to do with your [- -] and [! !]
sections living in a different scope. I can confirm the behaviour
but I could'nt find any other solution than putting the function
at the top of the page either.

Andre

--
 /"\
 \ /
  X  ASCII Ribbon campaign against HTML E-Mail
 / \