perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gerald Richter" <>
Subject RE: A bunch of glitches I'd like some help with
Date Sun, 04 Jun 2000 18:03:10 GMT
> (1) I have some fields that contain multi-line data (i.e. with
> embedded '\n'
> newlines).  To display these properly, I need to insert a <br>
> tag for each
> '\n'.  I can do a `s/\n/<br>/sg;', but I now I have two alternatives,
> neither of which work:

You need to escape the html tag:

[+ $foo =~ s/\n/\\\\<br\\>/g; $foo +]

or if you have optRawInput off:

[+ $foo =~ s/\n/\\<br\\>/g; $foo +]

(and use $escmode = 3, the default )

> (2) I want to turn on $optEarlyHeaders just for one or two scripts (not a
> whole directory).  There doesn't seem to be a way to do this (unless I've
> missed it).

Put a Files block inside your Location/Directory block that enables Embperl:

<Files file1.epl>
<Files file2.epl>

> What would be ideal (from my point of view) would be
> to have a
> call FlushOutput(),

Yes, that would be nices, but isn't so easy to implement. I put it on the
TODO list

> (3) The last thing was that I wanted to define a subroutine to
> call in case
> of fatal errors, to generate some output for the user, then abort the
> script.  However, all my attempts to end the routine with exit(0),
> Apache::exit(0) or even `die',

die only terminates the current [-/+ ... -/+] block

> were not working, and the routine kept on
> returning and continuing the execution.
> This is what I was doing (more or less):
>  [$ sub error $]
>  There was an error: [+ $_[0] +]
>  [- Apache::exit(0); -]
>  [$ endsub $]
>  ...
>  [-
>    do_something() || error("Can't do_something");
>  -]

The above code should work (also you need only to write exit(0)). One thing
is that exit only terminates the current file, so if you call this file from
another one via Execute, the other one will continue to run.

> That didn't work.  However, using a [! !] block for the subroutine
> containing the exit() call *did* work:
>  [! sub error { disp_error($_[0]); Apache::exit(0); } !]
>  [$ sub disp_error $]
>  There was an error: [+ $_[0] +]
>  [$ endsub $]

This is strange, both should do the same...

> This is all a bit weird, and I'm sure there is a good reason for it.  Is
> this the intended behaviour for exit(), Apache::exit() and die ?
> If so, it
> would be useful to have some discussion on this in the documentation

There is already something about exit:

- exit

exit will override the normal Perl exit in every Embperl document. Calling
exit will immediately stop any further processing of that file and send the
already-done work to the output/browser.

NOTE 1: If you are inside of an Execute, Embperl will only exit this
Execute, but the file which called the file containing the exit with Execute
will continue.

NOTE 2: If you write a module which should work with Embperl under mod_perl,
you must use Apache::exit instead of the normal Perl exit (just like always
when running under mod_perl).

If you, after solving your problem, have any ideas how to write it more
clear, please send me a patch


Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:         Voice:    +49 6133 925151
WWW:      Fax:      +49 6133 925152

View raw message