You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by PILCH Hartmut <ph...@a2e.de> on 2006/03/26 04:04:51 UTC

erratic effect of input key in Execute

At

	http://www.ecos.de/embperl/pod/doc/Config.-page-1-.htm#sect_3

I find the following example of how to invoke the Embperl parser from a Perl
program, and indeed I can make this work in a simple script, like

	 [- $msg = 'hello world' -]
	 <h3>[- Embperl::Execute({input=>\$msg}) -]</h3>

However, when I repeatedly invoke this with different messages, e.g.

  [- $msg = 'allo mir' -]
  <h3>1 [- hello('hello world') -]</h3>
  <h3>2 [- Embperl::Execute({input=>\$msg}) -]</h3>
  <h3>3 [- hallo('hallo welt') -]</h3>


where 'hello' and 'hallo' are subroutines that just invoke the same as above,
I always the same message three times.   Either it's 'hello world' or 'hallo
welt' or 'allo mir', no idea based on what.

It is as if Execute was using the same memory buffer for all three invocations
and as if that memory buffer was written in one run and used in another.

Setting

    mtime=>1

or

    mtime=>undef

doesn't change this behaviour either.

I'm using the Embperl 2.1.

--
Hartmut Pilch			   http://a2e.de/phm/adv/embperl








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


RE: printing to OUT from within a package /was: erratic effect of input key in Execute

Posted by Gerald Richter <ri...@ecos.de>.
> 
> > > 	[- print WEB "<h3>blablabla</h3>" -]
> > 
> > You need to print to OUT inside your Embperl code
> 
> That works too, except when I do this in a external package, e.g.
> 
> 

In an external package you need to tie a filehandle to Embperl::Out eg.

  tie OUT, 'Embperl::Out' ;

Gerald



 
** Virus checked by BB-5000 Mailfilter ** 


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


printing to OUT from within a package /was: erratic effect of input key in Execute

Posted by PILCH Hartmut <ph...@a2e.de>.
> > 	[- print WEB "<h3>blablabla</h3>" -]
> 
> You need to print to OUT inside your Embperl code

That works too, except when I do this in a external package, e.g.


foo/bar.pm

	package Foo::Bar;

	[...]

  	sub say1 {
	  print OUT "DEBUG1: ";
	  printf OUT @_;
 	  print OUT "\n";			
	} 

	__END__


saytest.htm

	[- use Foo::Bar qw(say1);
	   sub say2 {
	        print OUT "DEBUG2: ";
		printf OUT @_;
		print OUT "\n";
	   }
          -]
  	 
        <h3>[- say1 "foo" -]</h3>	
        <h3>[- say2 "bar" -]</h3>


This will print only 

	<h3></h3>
        <h3>DEBUG2: bar</h3>

				
Is the file descriptor OUT not accessible from the package ?

--
Hartmut Pilch		http://a2e.de/phm/adv/embperl/

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


RE: erratic effect of input key in Execute

Posted by Gerald Richter <ri...@ecos.de>.
> 
> > I now tried various definitions, such as
> > 
> > 
> >   sub say {
> > 	local $msg = shift;
> > 	Embperl::Execute({input=>\$msg, inputfile=>$msg});
> >   }
>  
> [...] 
>  
> > and am still getting always the same string printed out.
> 
> No, it does seem to be working for me now, thanks.
> 

Great!

> The latest failure was due to an error in my testing script.
> 
> This still leaves me with some questions open, such as 
> whether there is any way to replace 
> 
>  	<h3>blablabla</h3>
> 
> with
> 
> 	[- print WEB "<h3>blablabla</h3>" -]
> 

You need to print to OUT inside your Embperl code

> 
> Also: is there any risk in routinely using $msg as the value 
> for the inputfile key, regardless of its content ?  Or is it 
> better to generate a value like
> 
> 	$fi = sprint "file%d", ++$n ;
> 	Embperl::Execute({input=>\$src, inputfile=>$fi) ;
> 

Have $msg as the key makes sure that if you have two times the same code
Embperl will compile it only once, so that is ok, unless $msg will get too
long because Embperl will use it as hash key.

>...
> Also this usage scares me a bit, because 'inputfile' here 
> seems to be competing with 'input'.  How do I know Execute 
> reads its input from the variable pointer and not from a file 
> with the name specified in 'inputfile', which might exist.

When input => is present Embperl always takes input => as it's source

Gerald




 
** Virus checked by BB-5000 Mailfilter ** 


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


Re: erratic effect of input key in Execute

Posted by PILCH Hartmut <ph...@a2e.de>.
> I now tried various definitions, such as
> 
> 
>   sub say {
> 	local $msg = shift;
> 	Embperl::Execute({input=>\$msg, inputfile=>$msg});
>   }
 
[...] 
 
> and am still getting always the same string printed out.

No, it does seem to be working for me now, thanks.

The latest failure was due to an error in my testing script.

This still leaves me with some questions open, such as whether there is
any way to replace 

 	<h3>blablabla</h3>

with

	[- print WEB "<h3>blablabla</h3>" -]

or
	
	$title = "blablabla" ;
	$src = "<h3>[+ $title +]</h3>" ;
	Embperl::Execute({input=>\$src, inputfile=>$src, ouput=>\$out});
	print WEB $out ;

Also: is there any risk in routinely using $msg as the value for the
inputfile key, regardless of its content ?  Or is it better to generate
a value like

	$fi = sprint "file%d", ++$n ;
	Embperl::Execute({input=>\$src, inputfile=>$fi) ;

?


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


Re: erratic effect of input key in Execute

Posted by PILCH Hartmut <ph...@a2e.de>.
On Mon, Mar 27, 2006 at 08:52:03PM +0200, Gerald Richter wrote:
> > At
> > 
> > 	http://www.ecos.de/embperl/pod/doc/Config.-page-1-.htm#sect_3
> > 
> > I find the following example of how to invoke the Embperl 
> > parser from a Perl program, and indeed I can make this work 
> > in a simple script, like
> > 
> > 	 [- $msg = 'hello world' -]
> > 	 <h3>[- Embperl::Execute({input=>\$msg}) -]</h3>
> 
> You always need to specify the inputfile parameter (it doesn't matter with
> what value). Embperl used it as a cache key for the source code, so if you
> have different source code, you should use a different string as key to
> inputfile. 

I now tried various definitions, such as


  sub say {
	local $msg = shift;
	Embperl::Execute({input=>\$msg, inputfile=>$msg});
  }

or

  $n = 0;
  sub say {
	local $msg = shift;
	Embperl::Execute({input=>\$msg, inputfile=>++$n});	
  }



use My::Lib qw(hello) ; 

<h3>[- say('hello world') -]</h3>
<h3>[- say('hallo welt') -]</h3>

EOF

and am still getting always the same string printed out.

> See the examples on the web page you refering to.

I can't find any discussion on the use of inputfile as a cache key.

Also this usage scares me a bit, because 'inputfile' here seems to
be competing with 'input'.  How do I know Execute reads its
input from the variable pointer and not from a file with the
name specified in 'inputfile', which might exist.

Also, a most elegant solution for my purpose might be to
avoid Embperl::Execute altogether and just use 'print' or 'printf'
to send my message to the web interface.  After all the output=>
parameter also seems to default to STDOUT, so why not just print
to STDOUT ?  But when I attempt to do so, nothing shows up on the
web page.  Is there some other output stream to which I should possibly
be printing ?

--
Hartmut Pilch			   http://a2e.de/phm/adv/embperl






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


RE: erratic effect of input key in Execute

Posted by Gerald Richter <ri...@ecos.de>.
> At
> 
> 	http://www.ecos.de/embperl/pod/doc/Config.-page-1-.htm#sect_3
> 
> I find the following example of how to invoke the Embperl 
> parser from a Perl program, and indeed I can make this work 
> in a simple script, like
> 
> 	 [- $msg = 'hello world' -]
> 	 <h3>[- Embperl::Execute({input=>\$msg}) -]</h3>

You always need to specify the inputfile parameter (it doesn't matter with
what value). Embperl used it as a cache key for the source code, so if you
have different source code, you should use a different string as key to
inputfile. See the examples on the web page you refering to.


Gerald



 
** Virus checked by BB-5000 Mailfilter ** 


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