Prelim 5 - Unix Permissions

Debugging Perl scripts is a bear, and the most common problem concerns permissions, so that is what we will treat first.
  1. When a page refuses to show up on the screen

    Try the following in the Unix window. Let's say the script's name is test.pl. Issue the command
    test.pl
    
    and see what happens. If the machine responds that there is no such command, then you know that test.pl does not have execute permission.
    Issue the command
     chmod a+x test.pl
    and see if when one repeats the command
    test.pl
    
    and this second time one sees something wierd, i.e.,
    (offline mode: enter name=value pairs on standard input)
    then you know that the permissions were your problem. By the way, to see what happens next, hold down the control key and press the `d' key and you will see your script execute.
    chmod is an instruction which changes the permissions on a file. a+x says change the user, group, and other's permission to include execute as a possibility. This makes test.pl executable (runable as a program) rather than a text file. To see this issue the command
    ls -al test.pl
    
    and you will see something funny on the left hand side:
    -rwxr-xr-x etc.,
    where r means read, w means write, and x means execute. The three groups are indicated as triples. The order is first user, then group, then other (world).
  2. When a page shows up empty on the screen, but there is no Net-based Error Message

    Try the following. Change the first character of every line but the first 4 and the last to comments by putting a `#' sign at position 1 of each line. Then a program would read:
    #!/usr/local/bin/perl -- -*- C -*-
    use CGI;
    $query = new CGI;
    print $query->header;
    print "This is a Title";
    #print <<EOF;
    #this is text which has been commented out
    #EOF
    print $query->end_html;
    
    and check that the title appears. Then try
    #!/usr/local/bin/perl -- -*- C -*-
    use CGI;
    $query = new CGI;
    print $query->header;
    print "This is a Title";
    print "this is a line of text";
    #print <<EOF;
    #this is text which has been commented out
    #EOF
    print $query->end_html;
    
    and see if the line `this is a line of text' appears. Once this is done, start logically removing the comments `#'.
  3. Another possibility is to set buffering off by inserting as the second line in your file, the special $|=1 instruction setting the $OUTPUT_AUTOFLUSH variable, which makes the output write immediately (to the browser's screen) rather than buffering it:
    #!/usr/local/bin/perl -- -*- C -*-
    $| = 1;
    use CGI;
    $query = new CGI;
    print $query->header;
    print "This is a Title";
    print "this is a line of text";
    #print <<EOF;
    #this is text which has been commented out
    #EOF
    print $query->end_html;
    
  4. Yet another possibility is to route the stderr output to the screen i.e., open(&STDERR,>>STDOUT) as in:
    #!/usr/local/bin/perl -- -*- C -*-
    open(&STDERR,>>STDOUT);
    use CGI;
    $query = new CGI;
    print $query->header;
    print "This is a Title";
    print "this is a line of text";
    #print <<EOF;
    #this is text which has been commented out
    #EOF
    print $query->end_html;
    
  5. There is yet one more way to get errors reported. Insert the lines
    use CGI::Carp qw(fatalsToBrowser);
    use diagnostics;
    
    after "use CGI". This will result in ouput showing up on your screen.
Of course, once the program is outputting something to the screen, judicious use of the print statement should lead to enlightenment. Remember to save the current version of test.pl, then reload it in your browser.
One last piece of business. Sometimes, the reload is not enough, and the disk buffer of the browser has to be emptied, which is controlled by some options of the browser. In fact, usually it is reasonable to make the disk cache of zero size, while debugging, which insures that reload always does what you want. This is my default setting!

There is a wonderful FAQ (Frequently Asked Questions) available here which is worth consulting when nothing I've given you is good enough.
Return to the last section (prelim4 - Unix editors -).
Return to the main book TOC.