Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Saturday, August 5, 2006

Perl - Issues

Problems encountered on 2006-07-31:

1. Today, for some reason, we are seeing the variables being passed via GET in URLs. This actually sounds more normal, I guess the question is why it wasn't happening before??!!

Solution
- Started calling CGI scripts using:
exec ( "perl my.cgi @sendArgs" );
instead of:
print "Location:my.cgi?arg1=$val1\n\n";


2. IE during file upload
my $uploadFile = param( 'uploadFile' );
sends the entire path, not just the file name.
C:\path\dreaming.zip

Firefox just sends the filename.

Must support both situations.

Solution
Here is the file spec, which varies from IE to Firefox.
my $uploadFile = param( 'uploadFile' );

So I extract the file name
my @pathArr = split( /\\/, $uploadFile );
my $pathEltCnt = scalar( @pathArr );
my $fileName = $pathArr[$pathEltCnt-1];

Some functions need the file spec as provided by the browser, in whatever form.
my $uploadInfo = uploadInfo( $uploadFile );
my $uploadType = $uploadInfo -> { 'Content-Type' };

Note that for opening I use $fileName, but for actual reading I use the original file spec.
open ( UPFILE, "> $dirName/$fileName" ) || die("Cannot open($fileName): $!");
binmode( UPFILE );
my ( $data, $chunk );
my $fileSize = 0;
while ( $chunk = read ( $uploadFile, $data, 1024 ) ) {
print UPFILE $data;
$fileSize += $chunk;
}
close ( UPFILE ) || die("Cannot close($fileName): $!");


Sunday, July 30, 2006

PHP - Numeric validation from forms

In the case where $quantity is a string like "aaa"
settype( $quantity, "integer" )

returns TRUE and $quantity becomes zero.

It is better to use is_numeric( $quantity )
This returns FALSE if $quantity is a string or blank.

Javascript - NaN

NaN means "not a number".

You cannot perform == or != operations against NaN.

NaN is not a string. And it is not a number either (duh!)

You
must use the function isNaN() to test for it.