This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric | |
function isNumeric(n) { return !isNaN(parseFloat(n)) && isFinite(n); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################# | |
# subroutine to trim off the white space, carriage returns, pipes, and commas from both ends of each string or array | |
sub trimErroneousCharactersAtEnds { | |
my $guy = shift; | |
return if !defined $guy; | |
my $type = (ref(\$guy) eq 'REF') ? ref($guy) : ref(\$guy); | |
if ( $type eq 'ARRAY') { # Reference to an array | |
foreach(@{$guy}) { #for each element in @{$guy} | |
s/\s+$//g; | |
s/,+$//g; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# line_break_check receives a file handle as its input and returns the new line character used in the file handle | |
sub line_break_check{ | |
my $file = shift; | |
local $/ = \1000; # read first 1000 bytes | |
local $_ = <$file>; # read | |
my ($newline) = /(\015\012?)/ ? $1 : "\012"; # Default to unix. | |
seek $file,0,0; # rewind to start of file | |
return $newline; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# formats floating point numbers so they print nicely | |
sub prettyPrintNumber{ | |
my $number = shift; | |
if(!$number){return "0.00";} | |
$number = ($number < 0.001) ? sprintf('%.2e',$number) : sprintf("%.3f",$number); | |
return $number; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# returns true if the value passed to it is numeric, false otherwise | |
sub isNumeric{ | |
no warnings; | |
use warnings FATAL => 'numeric'; | |
return 0 if(!defined $_[0] || $_[0] eq '' ); | |
return defined eval { $_[ 0] == 0 }; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'^[Y|y][A-Pa-p][L|R|l|r][0-9]{3}[W|w|C|c](?:-[A-Za-z])?$' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub does_table_exist { | |
# check wether tables exists in the database | |
my ($dbHandle, $tablename) = @_; | |
eval { $dbHandle->do("select count(*) from $tablename where 1=0") }; | |
if ($dbHandle->err) { | |
# Table does not exist | |
#print "Table $tablename does not exist.\n"; | |
return 0; | |
} | |
else { |