PERL, pack, and null varriables

software development

#1

I have the following PERL CGI code:

$EntryStruct = “a30 a12 a6”;

$query = new CGI;

$Header = $query->param(“bike_header”);
$Price = $query->param(“bike_price”);
$Stock = $query->param(“bike_stock”);

$EntryBuffer = pack($EntryStruct, $Header, $Price, $Stock);
open (ENTRY_LOG, “>>”, $BikeDB) || die “Sorry, can’t open database file $!”;
print ENTRY_LOG $EntryBuffer;
close (ENTRY_LOG);

When this modules is invoked from a form action in HTML everything works just fine as long as a I put something in all the fields. If I leave one of the fields blank when filling out the form, then an varriable is set to an ASCII string equivelent to the index in the pack. For example:

In the form form the HTML page, set:

bike_header = "This is a test"
bike_price = "$12,000"
but bike_stock was left blank

After the pack, $EntryBuffer has “2” in it where $Stock should be. I validated that $Stock is null. Why does this happen and more important, how do I ensure that $EntryBuffer has nulls in it after the pack when varriables I’m packing are null?

Thank you!


#2

Never mind - It was old debug code. I uploaded the wrong file