CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in
Add ListingModify ListingTell A FriendLink to TPASubscribeNew ListingsCool ListingsTop RatedRandom Link
Newest Reviews
  • review
  • hagen software
  • NOT GPL!
  • Hagan Software
  • Wasted Time with ...
  • poor pre-sale sup...
  • no response
  • rating the offer
  • Good Stuff
  • Good idea but use...


  •  
    Perl Archive : TLC : Programming : Perl : Intro to Perl Part 5: Customize a BigNoseBird
    Guide Search entire directory 
     

    Date Published: 1999-11-01

    Intro to Perl
    Main Page
    Part 1: Scalars
    Part 2: Arrays
    Part 3: Hashes
    Part 4: Subroutines
    Part 5: Putting it Together
    by D. Jasmine Merced
    TNS Group, Inc.

    Customizing a BigNoseBird

    To wrap up our Intro series, we're offering tips and ideas on how to customize a program to suit your needs. For this page, we'll use a popular program, birdtrap.cgi, by BigNoseBird. Birdtrap is a program that "traps" errors on your web site, such as the Bad Request (Error 400), Authorization Required (Error 401), Forbidden (Error 403), File Not Found (Error 404), Internal Server Error (500) and the really strange, don't know what to do with it "Unknown" error.

    If you wish to follow along with customizations, feel free to download birdtrap using one of the following download links:

    Download the source code for birdtrap.cgi: 102 tar unix file or 82k DOS file
    birdtrap.cgi home page

    Before you start customizing your programs, first make sure the program works on your server by installing and testing it. After you know it works, make a backup copy before you start customizing.

    You may also wish to read through the program once, at least reading the comments to see what belongs where. A lot of programmers include plenty of comments (in plain English), so you can understand what's going on.

    Customizations to birdtrap.cgi

    1. The first thing I always do when customizing a program is add a font variable that I can use throughout the program. I always put this near the other variables so they they're all in one place.

      So, near the top of birdtrap.cgi, I entered:

      $font = '<FONT FACE="Arial,Helvetica,sans serif" SIZE=2>';

      Now, anywhere in the program, I can simply add $font, and when an error page is displayed, it uses the font I want.

    2. The next thing I usually do is create two subroutines (or variables) for a header and a footer. Doing this will help make it easier to update the look of your page without having to copy and paste code throughout each output section. For example, birdtrap.cgi has 6 output pages, one for each of the errors.

      So, back to the top of birdtrap.cgi, but beneath $font. You can enter something like this:

      and then:

      Now, scroll down to the actual error messages. Let's take a look at the Error 400 (Bad Request) routine before we modify it:

      Now, a sample of the modified message:

      As you can see, this is a simpler way to make changes to all error pages simultaneously. The most important thing to remember is pay attention as to how the output is enclosed. birdtrap.cgi uses a different output delimeter for each error. Error 400 uses <<__400__ Error 404 uses <<__404__ and so forth. There must be a matching __400__ (or __404__ respectively) at the end of the text.

    3. The third item we'll deal with here is rather specific to birdtrap.cgi, and that is viewing the results of the error log that birdtrap.cgi generates. But since there many several programs that generate logs, but don't offer the ability to view logs without downloading it, I thought it would be a good addition. As usual, first the code, then the details.

      The following code will need to be added immediately after the $errorlog variable.

      The above code should look familiar... it's the code we used to describe loops in the New Perl Elements article this month. After you insert the above code, you'll just need to visit your birdtrap.cgi and add a ?viewlog to the end of your url (eg birdtrap.cgi?viewlog).

    If you'd like to see all of the customizations described above incorporated into the birdtrap.cgi file, you can get the customized birdtrap.cgi here.

    This concludes our "Intro to Perl" series. Use your imagination and the information you've learned to start customizing your own programs. The guidelines for perl's variables, arrays, hashes, and the rest are the same regardless of what program you've downloaded. Make sure you backup a working copy before customizing.

    Conclusion Home * Previous: Putting it all together

     

    D. Jasmine Merced is a partner in TNS Group, Inc. and the administrator of The Perl Archive. She also serves as a Director of the World Organization of Webmasters.

     
     


    About The Perl ArchiveLink Validation ProcessSearch Tips
    Web Applications & Managed Hosting Powered by Gossamer Threads
    Visit our Mailing List Archives