Constants

in Perl Tips, Miscellaneous
by William Ward on August 30, 2002 11:02 am

If your program uses certain values which are defined as global variables at the top of the program, and which are kept constant throughout the program (Example: a filename, hostname, URL, user ID, or some other static configuration value), consider using Perl’s "use constant" mechanism to define that value instead. Here’s what it looks like:

  use constant data_file => "/home/bill/data.txt";
  use constant pi        => 3.14159;

(more…)

Octal, Hexadecimal, And Decimal Conversion

in Perl Tips, Miscellaneous
by William Ward on August 15, 2002 3:20 pm

Perl offers a variety of ways to convert numbers from one form to another (remember, "There’s More Than One Way To Do It").

(more…)

CGI Debugging

in Perl Tips, Miscellaneous
by William Ward on August 9, 2002 3:31 pm

When programming CGI scripts for a web-based application, one common problem is that if there is an error all you see is "Internal Server Error" and you have to go look in the server’s log file for details. But sometimes you don’t have access to the log file, such as when it is hosted on an ISP’s server. Here’s a way to get those errors sent to the screen where they can be of use to you.

(more…)

Text::Wrap

in Perl Tips, Miscellaneous
by William Ward on August 2, 2002 8:31 am

Try the Text::Wrap module if you need to reformat text to fit in an 80 character window, or whatever other size you might need. This is a module that comes with Perl, so you don’t have to worry about installing it or whether it will be installed on a machine you will be running your programs on.

(more…)