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
open(FILE,"<$cgidir/image.gif");
binmode(FILE); # Specify Binary mode for file
binmode(STDOUT); # Specify Binary mode for output
print "Content-type: image/gif\n\n";
while (
Perl replacements for common system commands
I'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.
### ERASE
unlink("$cgidir/file.dat");
### RENAME
rename("$cgidir/oldfile.dat","$cgidir/newfile.dat");
### COPY
open(FILE1,"<$cgidir/file1.dat");
open(FILE2,">$cgidir/file2.dat");
binmode(FILE1);
binmode(FILE2);
while (
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
This article was originally published on December 4, 1998