Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

So, I never thought anyone would care about some of my programming stories, even those that were wildly successful because of Perl. But, over the last few years, I have seen an interest in Perl Success Stories here at the monastery; perhaps because it is reassuring to see that other people find Perl helpful, and maybe it is that some of these stories can be quite interesting. So, here I offer one of my earlier stories, hopefully one you will find inspiring and amazing, or at least funny.

Perl is a great friend to know. He is there when you need him. When you don't, he steps back and quietly waits. He doesn't get jealous while you are checking out that new scripting language to see if it isn’t any good. He doesn't get upset when you choose another language for a project. He just hangs out, always there if you need any help.

Our company just picked up a new client. They had an aging system, on the verge of failure. They needed system upgrading quick. They had several home-grown applications running against a central database server. The applications were written in a language/environment called SQL Windows 5. SQL Windows was an IDE with similar goals to Visual Basic. It provided drag-and-drop GIU design, fill-in-the-event based development, and built-in database server integration that was never intended for the load they were creating.

SQL Windows wasn't a very nice IDE, either. It may have been OK in its day, but at this time VB 6 was the standard, and in comparison a far better product. For example, the IDE forced you to write code in an outline. You find your window, expand it, find your event, expand it, right-click and insert a new statement, type a little, and so on. Each statement had to be added to this outline. There was no free-text editing of the language within the IDE. I never liked VB much, but I would gladly choose it over this product any day.

So, I successfully upgraded their database to SQLServer. Now I needed to do something about their code base. We chose to port their code to VB6 due to the many similarities in functionality and operation of the two languages. The problem was; I had the file with 70,000 lines of SQLWindows code, a language I knew nothing about.

Most of this file was meta information describing the various properties set for each of the form windows and their contents. It also included definitions for functions and implementations for event handlers, initialization of variables and the structure of classes. Here is a small example:

.head 6 + Pushbutton: pbDoIt .head 7 - Class Child Ref Key: 5 .head 7 - Class ChildKey: 17 .head 7 - Class: ADV_frmM_DynSql .head 7 - Property Template: .head 7 - Class DLL Name: .head 7 - Title: Prev .head 7 - Window Location and Size .head 8 - Left: 0.833" .head 8 - Top: 0.06" .head 8 - Width: 0.7" .head 8 - Width Editable? Class Default .head 8 - Height: 0.536" .head 8 - Height Editable? Class Default .head 7 - Visible? Class Default … .head 5 + On SAM_Click .head 6 + If SalMessageBox( 'Register ' || sName || ' to ' || sJobNum + || ' - ' || SalNumberToStrX( nSession, 0 ) || '?', 'Notice', MB_WarningYe +sNo ) = IDYES .head 7 - Set nDefault = SalListQuerySelection ( lbDefaults ) .head 7 + If nDefault = LB_Err .head 8 - Call SalMessageBox( 'Select a default first.', 'Notice', MB +_WarningOk ) .head 8 - Return FALSE

The .head tells the level of nesting of this line in the outline. The +/- tells whether the outline item was expanded in the IDE (doesn't matter to me).

It was obvious that most of the meta information could be converted directly to VB. Things like the form windows, their sizes, their contents, the size, location, and other properties of their contents, menus, event handlers, variables, functions and classes could all be ported. If I could convert everything except the code itself, it would save me an enormous amount of time. In fact, I wanted to convert their entire code base (70K LOC) in a week. Also, I wanted something that could be used on other SQLW projects, since they had several other applications that would need to be ported later.

The only thing standing in my way was I didn't know the entire structure of the file, nor did I want to learn it. I wanted to be able to pull out bits and pieces as I needed them, ignoring the rest. Unfortunately, it would be very hard to parse if I could not determine what lines were meta data and what were lines of actual code on a per-line basis.

Here is where I got lucky. It turns out that each line of code in the language always starts with a comment char (!), or one of eleven keywords. I hit the jackpot!

I whipped out Perl and wrote a script to convert the code to… XML! You are probably wondering "Oh, why did he have to shoe-horn XML into this mess?". It is an odd choice. The outline-oriented structure of the code base lent itself to XML very well, and the declarative nature of XSLT made it very easy to generate all of the VB files needed without having to do complex data queries/lookups. There were some minor issues. Normally in XML whitespace is not as significant as it is in code, so it can be a bit trying to get code to format they way you want when generating it with XSLTs.

Regardless, after a couple of days of tweaking the stylesheets, I could start porting all of the commented-out SQLW code I included in my VB files. I few helper libraries made that a trivial task. I realized I could have gone a step further and used Perl to convert the majority of SQLW syntax to VB too.

I never explicitly planned to use Perl in this project. It was something that just came up. And when I needed it, it was there and it saved the day (and months of development time).

I have studied and used scores of languages from C to VB, Java to Python, Ruby, PHP, even more esoteric ones like Prolog and LISP. None has ever been a side-kick to me like Perl. I program full-time in Perl now. Aside from giving me a source of income, Perl is there when I need an laugh (often in the form of an obfu, or crazy feature), and when I need a distraction (anyone for golf?), and often saves my @$$ when I screw up. Thanks Larry!

PS: I will try to make my next Perl Success Story a little shorter. :-)

Ted Young

($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)

In reply to A Perl Success Story by TedYoung

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (6)
    As of 2017-03-28 03:04 GMT
    Find Nodes?
      Voting Booth?
      Should Pluto Get Its Planethood Back?

      Results (326 votes). Check out past polls.