| Article: |
VBScript or Perl? | |
| Subject: | More considerations | |
| Date: | 2003-11-24 14:30:54 | |
| From: | brianiac | |
|
VBScript Strengths [Formatting Functions] FormatCurrency(), FormatDateTime(), FormatNumber(), and FormatPercent() not only make short work of tedious formatting tasks, but also use locale-specific formatting rules. [Data Conversion] CBool(), CByte(), CCur(), CDate(), CDbl(), CInt(), CLng(), CSng(), CStr(), CBool() all tend to overreact to unconvertable data, but are nicely complemented by VarType(), IsDate(), IsEmpty(), IsNull(), IsNumeric(), and IsObject(). Hex() and Oct() allow converting numbers to non-decimal strings. DateValue() and TimeValue() allow returning just the parsed date or time values, respectively. [Date/Time Support] Along with the usual functions for individual date fields, Day(), Hour(), Minute(), Month(), MonthName(), Second(), Timer(), Weekday(), WeekdayName(), Year(), and the more generic DatePart(), there are some more granular functions for current info: Now(), Date(), Time(). The DateSerial() and TimeSerial() functions allow for complex date arithmetic, as do DateAdd(), DateDiff(). Date literals are supported, using # as the delimiter: #datestring#.
|
||
Showing messages 1 through 4 of 4.
-
Function Pointers
2004-05-11 20:14:46 tby@yehl.us [Reply | View]
It is possible to get a "function pointer" in VBS: GetRef.
-
More considerations
2003-12-31 02:08:28 anonymous2 [Reply | View]
"all JScript arrays are hashes: an array with numeric keys can have string keys added, and all keys can be iterated via the for...in loop. As Perl programmers already know, native hash support allows arbitrarily complex data structures to be built quite easily."
Actually, JScript (ECMAScript) support of associative arrays is not very useful. You cannot get as the keys (indices) and let's say sort them, as you can in Perl. This prevents popular data-structures, such as frequency hashes.
For example this functionality of Perl would be quite impossible under Perl.
foreach $key (sort {$a <=> $b} keys %hash) {
printf "%s %s", $hash{$key} $key
}
However, this could be emulated in JScript (or any other language) using array of an array.
Another nice thing about Perl, not found in other languages is list/array slicing, such as this:
foreach $line (<FILE>) {
my ($empno, $name, $salary) = (split /,/)[0,2,4];
}
The above slices out the 1st, 3rd, and 5th elements of a CSV file and stores them into local variables called empno, name, and salary. In JScript, this gets a little ugly, and in other languages it gets uglier.
- Joaquin Menchaca -
More considerations
2004-01-06 08:14:11 brianiac [Reply | View]
Extracting keys from a JScript array is ugly, but not impossible:
var hash= { 'one': 'first', ... }, keys= {};
for(key in hash) keys.push();
keys= keys.sort();
Slicing is also supported, though only for contiguous regions:
var slice234= arr.slice(2,4);
-
More considerations
2003-11-30 12:03:53 anonymous2 [Reply | View]
1) I definitely would not take the formating functions of VBScript as a strong point. They are almost useless. Using the system locale specific rules is quite often a bad idea. Especialy for web based projects and for log files. I would really love to get logfiles with differently formated dates from different computers.
But you are right, it's a surprise there is at least this.
2) Data conversion in VB is also horrible. Especialy thanks to the complete evaluation of conditions. The fact that I can't write
IF IsNumeric(foo) AND CInt(foo) > 0 Then
is driving me crazy every time I have to use VB(Script).
Jenda



