Cross-platform Perl/CGI tips and tricks
Another issue is that Windows treats binary files and text files differently, so if you're trying to read or write a binary file, you'll get corrupted data, unless you specify that the file is to be read or written in binary mode.
### Read Binary file on Windows
binmode(FILE); # Specify Binary mode for file
binmode(STDOUT); # Specify Binary mode for output
print "Content-type: image/gif\n\n";
Perl replacements for common system commandsI've seen many CGI programs that would work beautifully on any server except for one simple thing. Where the programmer needed to copy, rename, or erase a file, instead of doing it in Perl he just used an operating system specific shell command (e.g.,
system("cp $file1 $file2");
Here are some 100 percent Perl-based alternatives to common system commands that will work on any operating system.
By using a few simple tricks and tips like these, you'll not only be saving time but writing better programs too! If you have any tricks and tips of your own you would like to share, drop me a line.
Dave Edis is president of Edis Digital, a new media solutions firm in Vancouver, Canada. Edis Digital develops Web-based publishing tools and applications for companies around the world.
Page 2 of 2