perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Peters <...@aguazul.demon.co.uk>
Subject A bunch of glitches I'd like some help with
Date Thu, 01 Jun 2000 19:51:31 GMT
Dear all -

I'm just getting into EmbPerl (very nice!), but I'm coming across a few
difficulties.  I'm wondering if there is a better way of doing what I want
to do.  I'm using version 1.2.1 on Debian, with Apache mod_perl.


(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:

- Output with $escmode==0, but then all my [<>&] characters are wrong
- Output with $escmode==3, but then I just get 4-characters "<br>" where
  I want my tags to be

Maybe one solution would be to manually do the [<>&] conversion, then
substitute the <br>, and output $escmode==0, which is a bit of a mess.  What
I ended up with was this, which isn't much better, putting an extra <br> on
the end, but it works for now:

 <td>
  [$ foreach $lin (split(/\n/, $dat[$row])) $] 
  [+$lin+]<br> 
  [$ endforeach $]
 </td>

Is there a better way to do this that I've missed ?


(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).  What would be ideal (from my point of view) would be to have a
call FlushOutput(), or something like that, that would flush the headers and
all the buffered output out to the browser, and from then on go into
$optEarlyHeaders mode.  This would be particularly useful for pages that
generate output for the user, and then do a lot of background updates
(mail-sending, whatever) before finishing.  We don't have to make the user
wait for all that to finish.  Is there some way of doing this that I've
missed ?


(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', 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");
 -]

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 $]

I did actually try putting the subroutine in a [- -] block initially, and
that didn't work either, but I can't get it to go wrong in the simple case
now - maybe it's connected with [$ if $] blocks as well.  I can try to
reproduce that example again if this is important to find a bug.

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 - on
how to successfully abort the script, and why what I tried wasn't working.
This is quite confusing.


Thanks -

Jim

-- 
 Jim Peters         /             __   |  \              Aguazul
                   /   /| /| )| /| / )||   \
 jim@aguazul.      \  (_|(_|(_|(_| )(_|I   /        www.aguazul.
  demon.co.uk       \    ._)     _/       /          demon.co.uk

Mime
View raw message