Glad to be able to give something back.  Note though that I don't know if this code is optimized like C's switch statement. Far as I know, Perl just sees another for loop--but I can't swear to that!  Maybe someone else knows for sure?

BTW, the imitation switch idea came from the camel book (2nd edition, p.105), so any kudos go to the usual suspects.

Deane



[EMAIL PROTECTED]

03/10/2006 10:36

       
        To:        [EMAIL PROTECTED]
        cc:        [email protected], [EMAIL PROTECTED], "Lynn. Rickards" <[EMAIL PROTECTED]>
        Subject:        Re: WIN32::OLE and M$Excel



[EMAIL PROTECTED] wrote on 03/10/2006 11:21:47 AM:

>
> One thing I saw... You can replace all that if...elsif...elsif...
> elsif... stuff with an imitation switch. Like this:
>
> for ($Examine[0]) {
>    /Uptime:\s+(\w.*)/i         && do { $ws->Cells($row, "E")
> ->{'Value'} = "$1"; last; };
>    /Kernel version:\s+(\w.*)/i && do { $ws->Cells($row, "F")
> ->{'Value'} = "$1"; last; };
>    /Product type:\s+(\w.*)/i   && do { $ws->Cells($row, "G")
> ->{'Value'} = "$1"; last; };
>    # usw.
> }
>
> Lots cleaner, and, if I'm not mistaken, faster. I built a whole
> translation sub using nothing more than this trick.  One hint for
> speed--if there are possibilities that get "hit" more frequently
> than others, although that doesn't seem the case here, put them at the
top.
>
> Deane
THNX!!! havent seen the imitation switch before. i know in c and php that
the switch is written so that the code driving it is more efficient.
i will definitely use this.

Josh

-----------------------------------------
PLEASE NOTE:
SeaChange International headquarters in Maynard, MA is moving!
Effective March 1, 2006, our new headquarters address will be:

SeaChange International
50 Nagog Park
Acton, MA 01720 USA

All telephone numbers remain the same:
Main Corporate Telephone: 978-897-0100
Customer Service Telephone: 978-897-7300



_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to