August 30th, 2002
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;
Read the rest of this entry »
Posted in Miscellaneous, Perl Tips | No Comments »
August 15th, 2002
Perl offers a variety of ways to convert numbers from one form to another (remember, "There’s More Than One Way To Do It").
Read the rest of this entry »
Posted in Miscellaneous, Perl Tips | 10 Comments »
August 9th, 2002
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.
Read the rest of this entry »
Posted in Miscellaneous, Perl Tips | No Comments »
August 2nd, 2002
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.
Read the rest of this entry »
Posted in Miscellaneous, Perl Tips | 10 Comments »
July 29th, 2002
Normally, reading from a file is done one line at a time. But sometimes that is not very convenient. What if you want to read in text one paragraph at a time? Or maybe your data is separated by TAB characters rather than newline characters?
Read the rest of this entry »
Posted in Files & Directories, Perl Tips | 3 Comments »
July 21st, 2002
If you have an array that may contain the same value in several places, and you would like to sort the array and remove all duplicates, here’s one way to do it…
Read the rest of this entry »
Posted in Data Structures, Perl Tips | 1 Comment »