What I learned at the meeting last night. (2)

Alan Stewart astewart at spawar.navy.mil
Fri Oct 15 13:27:17 CDT 1999


~sdpm~
On 14 Oct 99 at 21:15, Joel Fentin wrote:

>~sdpm~
>In other languages, I can place a beep in the code to see if
>program execution passed through a specific area of the code.
>This does not work with the following example. I was told to use
> warn "something"; & 
>print STDERR __line__; . I don't seem to be able to use them to
>advantage.
>
>In the following program I wish to learn how to use them to see
>if execution flow passed through CCC.
>
>
>#!/perl/bin/perl -w
>use CGI::Carp qw(carpout fatalsToBrowser);      # sends errors to
>browzer
>use strict;
>use CGI qw(:standard);
>
>#main part of the program
>
>AAA();
>BBB();
>CCC();
>
>#end of main part of program
>
>
>#=========================================================
>sub AAA()
>  {print "\07";}                                # beeps don't work
>
>#=========================================================
>sub BBB(){
>  print header(), start_html("1");              # program won't
>work w/o this line
>  print end_html();                             # program won't
>work w/o this line
>}
>
>#=========================================================
>sub CCC()
>{
>  warn "something";                             #?
>  #print STDERR __line__;                       #?
>}
>
>--
>Joel Fentin    tel: 760-749-8863    FAX: 760-749-8864
>

After re-reading the CGI::Carp doc, I re-wrote it a little like this:
##############################################
#!/perl/bin/perl -w
# BEGIN block to set up re-direction before doing anything
BEGIN {
# qw(carpout) imports function to send non-fatal STDERR messages to a file
  use CGI::Carp qw(carpout fatalsToBrowser);
# this makes STDOUT the file that messages go to (to the browser)
  carpout(\*STDOUT);
# If you don't do carpout, they will only be in the server log
# this unbuffers STDOUT so messages flush out immediately
  $|=1;
# Otherwise, the HTML and warn messages don't intermix properly
}

use strict;
use CGI qw(:standard);

#main part of the program

BBB();
CCC();

#end of main part of program


#=========================================================
sub AAA() {
  warn "first thing";
}

#=========================================================
sub BBB() {
  print header(), start_html("1");
# the call to AAA() in the original code came before the start_html() and therefore 
# outside the HTML. The browser may not show it or it may screw up the rest of the 
# HTML parsing.
# Call it here inside the HTML.
  AAA();
# or just warn here, or put the header() and start_html() in the main program
  warn "second thing";
  print end_html();
}

#=========================================================
sub CCC() {
# This one is also outside the HTML but some browsers (Netscape) don't mind 
# tacking on some text after the HTML and displaying it (definitely non-standard).
  warn "third thing";
}
##################################################
---------------------------------------------------------------
Alan Stewart          )-[]-(           Electronics Engineer
Code D621           ~        ~         Network Operations
SPAWARSYSCEN       ~          ~  \     Satellite Communications
53560 Hull St   ( ~            ~  )    tel (619)524-3625
San Diego,CA  __|___             /|    fax (619)524-2607
92152-5001   ^\____/^^^^^^\    __| |_  astewart at spawar.navy.mil
------------^^^^^^^^^^^^^^^\__|______|_------------------------
~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list