Yahasp, a PerlHoo Alternative
A note from Jonathan
I'd like to personally thank Laurence Gold who has effectively duplicated the functionality of PerlHoo using an ASP VBscript app. While I still use Perl for most of my programming tasks (not just Web development), I think it's important to provide alternatives. Yahasp will also provide a basis for a side-by-side comparison of VBscript for ASP, and Perl for CGI which will be done at the end of the PerlHoo series.
Our friend Jonathan Eisenzopf has done a brilliant job building a Yahoo like directory in PERL. The problem though is that I run NT, and IIS. I tried to install PERL and all the necessary files, but was not able to get it to work. Than I remembered one of the criteria was it had to be developed in less than a week.
I thought it should be easy maybe even easier to write the same Yahoo like directory in ASP. ASP happens to be Microsoft's Server Side Scripting language for their Web server IIS. However, before I go into the code let us first look at the criteria.
- Organizes information hierarchically
- Contains information about resources on the Internet
- Allows users to suggest new resources
- Allows editors to modify the directory content
- Is simple to maintain
- Takes less than 1 week to develop
- Exports and imports directory content from/to multiple sources
Jonathan is on version II of Perlhoo so this article will catch up that to version. I have also attempted to keep the same structure so it may not be typical ASP programming. I have also decided to keep the same Open Source Licensing. Thus, maybe some other ASP programmers will make it better. Therefore, this version I will attempt to answer 1, 2, 3, 4 and 5 for the most part.
Catching up to PerlHoo, Part I
First, I agree with Jonathan, there is no need to spend time modeling a database when there is a perfectly good directory. I also use a text file to store links. This will easily allow us to accomplish #1 and #5, which is to organize the information hierarchically and is simple to maintain. Note that I have an extra field in the text file, this is the window frame name. I did this just in case I wanted to use this in a frame format.
The Subroutine YAHASP is what accomplished this task. I use the Scripting.FileSystemObject (line 45, 66 and 67) to get the directory from the operating system, using a simple loop (lines 68-76) to traverse through the directories and print them out. Please note I often mix ASP and HTML to make it easier to read. For speed purposes, it is faster to create the whole file in ASP. I again use the Scripting.FileSystemObject but the OpenTextFile (lines 89-90) method to read from the text file. Lines 93 through 103 loops through the text file reading the lines and parsing them. ASP Parsing is a little different than PERL, I use the Mid string function to get rid of the starting and ending quotes. Next I create a variable with the string '","' (that is double quote - comma - double quote). This string is used to parse the line with the "Split" Command. Finally, I close the file once done reading it.