Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.advocacy > #350996 > unrolled thread

A maybe interesting code challenge

Started byDFS <nospam@dfs.com>
First post2016-04-20 11:37 -0400
Last post2016-04-28 05:46 -0400
Articles 20 on this page of 140 — 16 participants

Back to article view | Back to comp.os.linux.advocacy


Contents

  A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-20 11:37 -0400
    Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-20 08:45 -0700
      Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-20 11:57 -0400
        Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-20 09:02 -0700
        Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-21 01:54 +0000
          Re: A maybe interesting code challenge Steve Carroll <fretwizzen@gmail.com> - 2016-04-20 18:57 -0700
          Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-21 02:45 +0000
            Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-20 23:01 -0400
              Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-21 03:56 +0000
                Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-21 11:06 -0400
                  Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-21 16:13 +0000
                    Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-21 17:27 -0400
                      Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-22 19:07 +0000
    Re: A maybe interesting code challenge Steve Carroll <fretwizzen@gmail.com> - 2016-04-20 19:01 -0700
    Re: A maybe interesting code challenge Fabian Russell <fb@zen.info> - 2016-04-22 09:37 +0000
      Re: A maybe interesting code challenge Norman Peelman <npeelman@cfl.rr.com> - 2016-04-22 08:33 -0400
        Re: A maybe interesting code challenge Fabian Russell <fb@zen.info> - 2016-04-22 22:03 +0000
          Re: A maybe interesting code challenge Richard King <kingsley651@webby.org> - 2016-04-22 18:22 -0400
      Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-22 19:48 +0000
        Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-22 17:24 -0400
          Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-22 22:18 +0000
            Re: A maybe interesting code challenge Fabian Russell <fb@zen.info> - 2016-04-22 22:26 +0000
              Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-22 22:43 +0000
                Re: A maybe interesting code challenge Fabian Russell <fb@zen.info> - 2016-04-22 22:50 +0000
                  Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-22 22:57 +0000
                    Re: A maybe interesting code challenge Fabian Russell <fb@zen.info> - 2016-04-23 13:07 +0000
                      Re: A maybe interesting code challenge Norman Peelman <npeelman@cfl.rr.com> - 2016-04-23 09:58 -0400
        Re: A maybe interesting code challenge Fabian Russell <fb@zen.info> - 2016-04-22 21:48 +0000
      Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-22 17:00 -0400
        Re: A maybe interesting code challenge Fabian Russell <fb@zen.info> - 2016-04-22 21:56 +0000
          Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-22 19:39 -0400
            Re: A maybe interesting code challenge Fabian Russell <fb@zen.info> - 2016-04-23 15:25 +0000
              Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-23 13:14 -0400
                Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-23 18:37 +0000
                  Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-23 16:50 -0400
                    Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-23 21:15 +0000
                      Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-23 18:36 -0400
                        Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-23 23:24 +0000
    Re: A maybe interesting code challenge Norman Peelman <npeelman@cfl.rr.com> - 2016-04-22 08:21 -0400
      Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-22 10:04 -0400
        Re: A maybe interesting code challenge Norman Peelman <npeelman@cfl.rr.com> - 2016-04-23 00:09 -0400
          Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-23 00:18 -0400
            Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-23 05:59 +0000
              Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-26 12:46 -0400
                Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-26 19:04 +0000
                  Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-26 20:40 +0000
                    Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-26 17:48 -0400
                      Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-26 22:14 +0000
            Re: A maybe interesting code challenge Norman Peelman <npeelman@cfl.rr.com> - 2016-04-23 23:15 -0400
              Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-23 23:30 -0400
                Re: A maybe interesting code challenge Norman Peelman <npeelman@cfl.rr.com> - 2016-04-24 08:52 -0400
                  Re: A maybe interesting code challenge Chris Ahlstrom <OFeem1987@teleworm.us> - 2016-04-24 10:06 -0400
                    Re: A maybe interesting code challenge Fabian Russell <fb@zen.info> - 2016-04-24 15:59 +0000
                Re: A maybe interesting code challenge Norman Peelman <npeelman@cfl.rr.com> - 2016-04-24 15:45 -0400
                  Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-25 10:19 -0400
                    Re: A maybe interesting code challenge Norman Peelman <npeelman@cfl.rr.com> - 2016-04-25 20:26 -0400
                      Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-25 23:24 -0400
                        Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-26 05:03 +0000
                          Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-26 11:40 -0400
    Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-25 15:14 +0000
      Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-25 12:05 -0400
        Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-25 18:06 +0000
          Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-26 12:41 -0400
            Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-26 18:03 +0000
              Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-26 17:39 -0400
                Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-27 05:50 +0000
                  Re: A maybe interesting code challenge chrisv <chrisv@nospam.invalid> - 2016-04-27 06:43 -0500
                    Re: A maybe interesting code challenge William Poaster <wp@dev.null> - 2016-04-27 13:11 +0100
                    Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-27 13:32 +0000
                  Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-27 07:32 -0700
                    Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-27 15:02 +0000
                      Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-27 08:17 -0700
                        Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-27 16:21 +0000
                          Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-27 09:42 -0700
                            Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-27 21:39 +0000
                              Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-27 23:25 +0000
                                Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-28 05:34 +0000
                                  Re: A maybe interesting code challenge vallor <vallor@cultnix.org> - 2016-04-28 05:37 +0000
                                    Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-28 05:42 +0000
                      Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-27 11:45 -0400
                        Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-27 16:23 +0000
                        Re: A maybe interesting code challenge Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-04-27 18:40 +0200
                          Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-27 09:58 -0700
                            Re: A maybe interesting code challenge Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-04-27 20:57 +0200
                              Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-27 12:06 -0700
                                Re: A maybe interesting code challenge Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-04-27 22:44 +0200
                  Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-27 13:38 -0400
                    Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-27 11:07 -0700
                      Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-27 15:51 -0400
                        Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-27 13:30 -0700
                          Re: A maybe interesting code challenge Norman Peelman <npeelman@cfl.rr.com> - 2016-04-27 21:38 -0400
                          Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-28 11:33 -0400
                            Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-28 09:14 -0700
                              Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-28 14:17 -0400
                                Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-28 18:49 +0000
                                  Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-29 08:42 -0700
                                    Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-29 13:42 -0400
                                      Re: A maybe interesting code challenge Snit <usenet@gallopinginsanity.com> - 2016-04-29 10:54 -0700
                                        Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-29 11:20 -0700
                                        Re: Snit digest 214 / 2016-04-29 Melzzzzz <mel@zzzzz.com> - 2016-04-30 00:31 +0200
                                        Re: Snit digest 214 / 2016-04-29 DFS <nospam@dfs.com> - 2016-04-29 19:00 -0400
                                          Re: Snit digest 214 / 2016-04-29 DFS <nospam@dfs.com> - 2016-04-30 10:36 -0400
                                        Re: Snit digest 214 / 2016-04-29 chrisv <chrisv@nospam.invalid> - 2016-05-02 07:54 -0500
                                          Re: Snit digest 214 / 2016-04-29 Peter Köhlmann <peter-koehlmann@t-online.de> - 2016-05-02 15:55 +0200
                                          Re: Snit digest 214 / 2016-04-29 Snit <usenet@gallopinginsanity.com> - 2016-05-02 07:23 -0700
                                            Snit digest 215 / 2016-05-02 Sandman <mr@sandman.net> - 2016-05-02 14:39 +0000
                                              Re: Snit digest 215 / 2016-05-02 Snit <usenet@gallopinginsanity.com> - 2016-05-02 07:54 -0700
                                          Re: Snit digest 214 / 2016-04-29 Sandman <mr@sandman.net> - 2016-05-02 14:36 +0000
                                            Re: Snit digest 214 / 2016-04-29 Snit <usenet@gallopinginsanity.com> - 2016-05-02 07:53 -0700
                                      Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-29 11:11 -0700
                                    Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-29 14:44 -0700
                                    Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-29 17:53 -0400
                                      Re: A maybe interesting code challenge Melzzzzz <mel@zzzzz.com> - 2016-04-29 23:56 +0200
                                        Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-29 18:09 -0400
                                        Re: A maybe interesting code challenge Chris Ahlstrom <OFeem1987@teleworm.us> - 2016-04-29 19:09 -0400
                                      Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-30 07:31 -0700
                                        Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-05-01 08:21 +0000
                                        Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-05-01 08:47 -0700
                                      Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-05-02 14:54 -0400
                                        Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-05-02 21:54 -0400
                            Re: A maybe interesting code challenge GreyCloud <mist@cumulus.com> - 2016-04-28 15:39 -0600
                              Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-29 08:48 -0700
                                Re: A maybe interesting code challenge GreyCloud <mist@cumulus.com> - 2016-04-29 16:57 -0600
                        Re: A maybe interesting code challenge Norman Peelman <npeelman@cfl.rr.com> - 2016-04-27 21:33 -0400
                          Re: A maybe interesting code challenge Chris Ahlstrom <OFeem1987@teleworm.us> - 2016-04-28 05:45 -0400
                    Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-27 21:32 +0000
                      Re: A maybe interesting code challenge Norman Peelman <npeelman@cfl.rr.com> - 2016-04-27 21:48 -0400
                        Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-27 22:57 -0400
                          Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-28 05:44 +0000
                            Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-29 16:32 -0400
                        Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-27 23:05 -0400
                          Re: A maybe interesting code challenge owl <owl@rooftop.invalid> - 2016-04-28 03:20 +0000
                            Re: A maybe interesting code challenge DFS <nospam@dfs.com> - 2016-04-28 09:52 -0400
                              Re: A maybe interesting code challenge Norman Peelman <npeelman@cfl.rr.com> - 2016-04-29 02:46 -0400
                                Re: A maybe interesting code challenge Steve Carroll <fretwizzer@gmail.com> - 2016-04-29 08:33 -0700
                                  Re: A maybe interesting code challenge Norman Peelman <npeelman@cfl.rr.com> - 2016-04-30 09:31 -0400
                        Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-28 05:42 +0000
                          Re: A maybe interesting code challenge vallor <vallor@cultnix.org> - 2016-04-28 06:17 +0000
                            Re: A maybe interesting code challenge Sandman <mr@sandman.net> - 2016-04-28 06:56 +0000
                            Re: A maybe interesting code challenge Chris Ahlstrom <OFeem1987@teleworm.us> - 2016-04-28 05:46 -0400

Page 3 of 7 — ← Prev page 1 2 [3] 4 5 6 7  Next page →


#351407

FromNorman Peelman <npeelman@cfl.rr.com>
Date2016-04-23 00:09 -0400
Message-ID<nfesbh$hsk$1@dont-email.me>
In reply to#351253
On 04/22/2016 10:04 AM, DFS wrote:
> On 4/22/2016 8:21 AM, Norman Peelman wrote:
>> On 04/20/2016 11:37 AM, DFS wrote:
>>> Parse a search string composed of 1, 2 or 3 parts, separated by a
>>> semicolon, into 2, 4 or 6 variables (field1, value1, etc)
>>>
>>> Search string:
>>> use 1 part : state=GA
>>> use 2 parts: state=GA ; name = Burger King
>>> use 3 parts: state=GA ; name = Burger King ; zip like 303*
>>>
>>> The goal is to split it up like this:
>>>
>>> if 1 part used:
>>>   var field1 = 'state'
>>>   var value1 = 'GA'
>>>   other vars empty
>>>
>>> if 2 parts used:
>>>   var field1 = 'state'
>>>   var value1 = 'GA'
>>>   var field2 = 'name'
>>>   var value2 = 'Burger King'
>>>   other vars empty
>>>
>>> if 3 parts used:
>>>   var field1 = 'state'
>>>   var value1 = 'GA'
>>>   var field2 = 'name'
>>>   var value2 = 'Burger King'
>>>   var field3 = 'zip'
>>>   var value3 = '303*'
>>>
>>> It's harder than it looks, because the code has to handle 1, 2 or 3
>>> parts, you have to split on = or like, there's no quotes to keep Burger
>>> King together, and there can be no leading or trailing spaces when the
>>> values are stored.  Your code also has to declare at least those 6
>>> variables.
>>>
>>> =======================================================================
>>>
>>> My VBScript solution, which works fine, is:
>>> 21 lines of parsing logic
>>>   1 line for the variables
>>>   4 lines of procedure declaration
>>>   5 comments
>>>   4 'for testing' lines
>>>
>>>
>>> call parseString("state=GA")
>>> call parseString("state=GA ; name = Burger King")
>>> call parseString("state=GA ; name = Burger King ; zip like 303*")
>>>
>>>
>>> Private Function parseString(srLine)
>>>
>>> dim criteria,fld1,val1,fld2,val2,fld3,val3
>>>
>>>
>>> 'count semicolons in search line, and add 1
>>> 'this is how many search criteria are being used
>>> criteria = (Len(srLine)-Len(replace(srLine,";",""))) + 1
>>>
>>>
>>>
>>> 'parse search string into components
>>> If criteria >= 1 Then
>>>   fld1  = Trim(Split(srLine,spChar(srLine))(0))
>>>   val1  = Trim(Split(srLine,spChar(srLine))(1))
>>> End If
>>>
>>> If criteria >= 2 Then
>>>   fld1  =
>>> Trim(Split(Split(srLine,";")(0),spChar(Split(srLine,";")(0)))(0))
>>>   val1  =
>>> Trim(Split(Split(srLine,";")(0),spChar(Split(srLine,";")(0)))(1))
>>>   fld2  =
>>> Trim(Split(Split(srLine,";")(1),spChar(Split(srLine,";")(1)))(0))
>>>   val2  =
>>> Trim(Split(Split(srLine,";")(1),spChar(Split(srLine,";")(1)))(1))
>>> End If
>>>
>>> If criteria = 3 Then
>>>   fld1  =
>>> Trim(Split(Split(srLine,";")(0),spChar(Split(srLine,";")(0)))(0))
>>>   val1  =
>>> Trim(Split(Split(srLine,";")(0),spChar(Split(srLine,";")(0)))(1))
>>>   fld2  =
>>> Trim(Split(Split(srLine,";")(1),spChar(Split(srLine,";")(1)))(0))
>>>   val2  =
>>> Trim(Split(Split(srLine,";")(1),spChar(Split(srLine,";")(1)))(1))
>>>   fld3  =
>>> Trim(Split(Split(srLine,";")(2),spChar(Split(srLine,";")(2)))(0))
>>>   val3  =
>>> Trim(Split(Split(srLine,";")(2),spChar(Split(srLine,";")(2)))(1))
>>> End If
>>>
>>> 'for testing
>>> wscript.echo "'" & fld1 & "' - '" & val1 & "'"
>>> wscript.echo "'" & fld2 & "' - '" & val2 & "'"
>>> wscript.echo "'" & fld3 & "' - '" & val3 & "'"
>>> wscript.echo "----------------------------"
>>>
>>> End Function
>>>
>>>
>>> 'parse on = or like
>>> Function spChar(lineToSplit)
>>>    spChar = "="
>>>    If InStr(lineToSplit,"like") > 0 Then spChar = "like"
>>> End Function
>>> =======================================================================
>>>
>>>
>>> If someone posts a 2-line perl solution, I'm hurling.
>>>
>>
>>
>> So, wouldn't it be more efficient as:
>>
>> tmpc = Split(srLine,";")
>> criteria = tmpc.Length
>>
>> ...
>>
>> if criteria = 1 then
>>    fld1 = Split(srLine,spChar(Split(srLine))
>> endif
>>
>> if criteria = 2 then
>>    fld1 = Split(srLine,spChar(Split(srLine))
>>    fld2 = Split(srLine,spChar(Split(srLine))
>> endif
>>
>> if criteria = 3 then
>>    fld1 = Split(srLine,spChar(Split(srLine))
>>    fld2 = Split(srLine,spChar(Split(srLine))
>>    fld3 = Split(srLine,spChar(Split(srLine))
>> endif
>>
>> ...
>>
>> wscript.echo "'" & Trim(fld1(0)) & "' - '" & Trim(fld1(1)) & "'"
>> wscript.echo "'" & Trim(fld2(0)) & "' - '" & Trim(fld2(1)) & "'"
>> wscript.echo "'" & Trim(fld3(0)) & "' - '" & Trim(fld3(1)) & "'"
>>
>>
>>
>>    No code tested... just thoughts.
>
>
> Thanks, but it won't run in VBSCript.
>

   So, (curiosity) what is wrong with it?  Anyway, you do understand 
that you are doing unnecessary work by having:

criteria >= 1  -- every time criteria is 1,2 or 3 these lines run
criteria >= 2  -- every time criteria is 2 or 3 these lines run

[toc] | [prev] | [next] | [standalone]


#351408

FromDFS <nospam@dfs.com>
Date2016-04-23 00:18 -0400
Message-ID<nfessd$j35$1@dont-email.me>
In reply to#351407
On 4/23/2016 12:09 AM, Norman Peelman wrote:

>    So, (curiosity) what is wrong with it?


A bunch of stuff I didn't want to track down and fix.

VBScript has some significant differences from VB/A.

If you develop and test under VBScript you'll see.



> Anyway, you do understand
> that you are doing unnecessary work by having:
>
> criteria >= 1  -- every time criteria is 1,2 or 3 these lines run
> criteria >= 2  -- every time criteria is 2 or 3 these lines run


Yes, I recognized that immediately after I posted it.  The fix shaved 
0.014 seconds off run time.

[toc] | [prev] | [next] | [standalone]


#351414

Fromowl <owl@rooftop.invalid>
Date2016-04-23 05:59 +0000
Message-ID<ghjd03af.h8h@rooftop.invalid>
In reply to#351408
DFS <nospam@dfs.com> wrote:
> On 4/23/2016 12:09 AM, Norman Peelman wrote:
> 
>>    So, (curiosity) what is wrong with it?
> 
> 
> A bunch of stuff I didn't want to track down and fix.
> 
> VBScript has some significant differences from VB/A.
> 
> If you develop and test under VBScript you'll see.
> 
> 
> 
>> Anyway, you do understand
>> that you are doing unnecessary work by having:
>>
>> criteria >= 1  -- every time criteria is 1,2 or 3 these lines run
>> criteria >= 2  -- every time criteria is 2 or 3 these lines run
> 
> 
> Yes, I recognized that immediately after I posted it.  The fix shaved 
> 0.014 seconds off run time.
> 

Your gonna hate me.  I figured the 2.7 sec was low for a C app.
I went over the code and removed some stupid shit and now baby's 
on fire.  The first one, "input_e", is the 6000 line input file
that gave me the 2.7 sec.  Now it's 0.048 sec.  :)  And a 600k
line file gets burned up in 1.376 sec, generating 3.6 million
lines of output. 

anon@lowtide:~/code/dfs/nah$ wc -l input_e
6000 input_e
anon@lowtide:~/code/dfs/nah$ wc -l input_60k
60000 input_60k
anon@lowtide:~/code/dfs/nah$ wc -l input_600k
600000 input_600k
anon@lowtide:~/code/dfs/nah$ rm output*
anon@lowtide:~/code/dfs/nah$ time ./blah input_e >output_e

real	0m0.048s
user	0m0.044s
sys	0m0.000s
anon@lowtide:~/code/dfs/nah$ time ./blah input_60k >output_60k

real	0m0.190s
user	0m0.180s
sys	0m0.008s
anon@lowtide:~/code/dfs/nah$ time ./blah input_600k >output_600k

real	0m1.376s
user	0m1.104s
sys	0m0.268s
anon@lowtide:~/code/dfs/nah$ wc -l output_e
36000 output_e
anon@lowtide:~/code/dfs/nah$ wc -l output_60k
360000 output_60k
anon@lowtide:~/code/dfs/nah$ wc -l output_600k
3600000 output_600k
anon@lowtide:~/code/dfs/nah$ tail output_600k
var field2 = 'name'
var value2 = 'Burger*'
var field3 = 'street'
var value3 = 'Main*'
var field1 = 'state'
var value1 = 'GA'
var field2 = 'name'
var value2 = '*pizza'
var field3 = 'zip'
var value3 = '30017'
anon@lowtide:~/code/dfs/nah$ 

[toc] | [prev] | [next] | [standalone]


#351982

FromDFS <nospam@dfs.com>
Date2016-04-26 12:46 -0400
Message-ID<nfo5ql$d1o$1@dont-email.me>
In reply to#351414
On 4/23/2016 1:59 AM, owl wrote:
> DFS <nospam@dfs.com> wrote:
>> On 4/23/2016 12:09 AM, Norman Peelman wrote:
>>
>>>     So, (curiosity) what is wrong with it?
>>
>>
>> A bunch of stuff I didn't want to track down and fix.
>>
>> VBScript has some significant differences from VB/A.
>>
>> If you develop and test under VBScript you'll see.
>>
>>
>>
>>> Anyway, you do understand
>>> that you are doing unnecessary work by having:
>>>
>>> criteria >= 1  -- every time criteria is 1,2 or 3 these lines run
>>> criteria >= 2  -- every time criteria is 2 or 3 these lines run
>>
>>
>> Yes, I recognized that immediately after I posted it.  The fix shaved
>> 0.014 seconds off run time.
>>
>
> Your gonna hate me.  I figured the 2.7 sec was low for a C app.
> I went over the code and removed some stupid shit and now baby's
> on fire.  The first one, "input_e", is the 6000 line input file
> that gave me the 2.7 sec.  Now it's 0.048 sec.  :)  And a 600k
> line file gets burned up in 1.376 sec, generating 3.6 million
> lines of output.

Nice.  Code or it didn't happen :)

You're not actually writing 3.6M lines to a file, right?

[toc] | [prev] | [next] | [standalone]


#352013

Fromowl <owl@rooftop.invalid>
Date2016-04-26 19:04 +0000
Message-ID<tuigo0af3@rooftop.invalid>
In reply to#351982
DFS <nospam@dfs.com> wrote:
> On 4/23/2016 1:59 AM, owl wrote:
>> DFS <nospam@dfs.com> wrote:
>>> On 4/23/2016 12:09 AM, Norman Peelman wrote:
>>>
>>>>     So, (curiosity) what is wrong with it?
>>>
>>>
>>> A bunch of stuff I didn't want to track down and fix.
>>>
>>> VBScript has some significant differences from VB/A.
>>>
>>> If you develop and test under VBScript you'll see.
>>>
>>>
>>>
>>>> Anyway, you do understand
>>>> that you are doing unnecessary work by having:
>>>>
>>>> criteria >= 1  -- every time criteria is 1,2 or 3 these lines run
>>>> criteria >= 2  -- every time criteria is 2 or 3 these lines run
>>>
>>>
>>> Yes, I recognized that immediately after I posted it.  The fix shaved
>>> 0.014 seconds off run time.
>>>
>>
>> Your gonna hate me.  I figured the 2.7 sec was low for a C app.
>> I went over the code and removed some stupid shit and now baby's
>> on fire.  The first one, "input_e", is the 6000 line input file
>> that gave me the 2.7 sec.  Now it's 0.048 sec.  :)  And a 600k
>> line file gets burned up in 1.376 sec, generating 3.6 million
>> lines of output.
> 
> Nice.  Code or it didn't happen :)
> 

Below.

> You're not actually writing 3.6M lines to a file, right?
> 
 

Yes.  I have since made some modifications to the code, so that it
handles an an arbirary number of input lines and allocates memory
based on file size.  Before it was hardcoded in arrays of fixed size.
(Still uses fixed max ending line length estimate of 128 bytes at this
point, as well as fixed field count of 6 based on initial count of ';',
so it's not completely robust yet).

This resulted in a speed decrease to about 2-3 sec IIRC for writing a 3.6
million line file.  Right now I have 8 instances of that md5/ip cracking
thing running, and times are way, off so I can't show a realistic
measure.

I didn't use the regex.h stuff -- just walked the file and did
byte comparisons.  I figured added function calls with regex
would be slower, but I might try it that way later and see what
happens.

----------------------- begin code ------------------------

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LINELENGTH 128

struct vars{
  char field1[LINELENGTH];
  char value1[LINELENGTH];
  char field2[LINELENGTH];
  char value2[LINELENGTH];
  char field3[LINELENGTH];
  char value3[LINELENGTH];
};


int main(int argc, char *argv[])
{
  int c=0;
  int i=0;
  int j=0;
  int k=0;
  long filesize=0;  

  FILE *fp=NULL;
  int newlinecount=0;
  int semicount=0;

  struct vars *varsarr;

  const char s[2]=";";
  char *token;

  char *sourcebuffer;
  char *targetbuffer;
  char *tempbuffer;

  if ( argc != 2 )
  {
   fprintf(stderr,"need a filename\n");
   exit(1);
  }

  char *inputfilename = argv[1];
  if( (fp=fopen(inputfilename,"r")) == NULL )
  {
    fprintf(stderr,"no file\n");
    exit(1);
  }
  fseek(fp,0,SEEK_END); 
  filesize=ftell(fp);
  fseek(fp,0,SEEK_SET);

  sourcebuffer = malloc(2 * filesize  +1 ); 
  if (sourcebuffer==NULL)
  {
    fprintf(stderr,"sourcebuffer malloc()\n");
    exit(1);
  }

  targetbuffer = malloc(2 * filesize  +1 ); 
  if (targetbuffer==NULL)
  {
    fprintf(stderr,"targetbuffer malloc()\n");
    exit(1);
  }

  while( (c=fgetc(fp))!= EOF )
  {
    if ( c == '\n' )
    {
       targetbuffer[i]=c;
       newlinecount++;
    }
    if ( c == ' ' )
    {
     targetbuffer[i++]=c;
      c=fgetc(fp); 
      if ( c == 'l' )
      {
        c=fgetc(fp); 
        if ( c == 'i' )
        {
           c=fgetc(fp);
           if( c == 'k' )
           {
              c=fgetc(fp);
              if( c == 'e' )
              {
                c=fgetc(fp);
                if ( c == ' ' )
                {
                  targetbuffer[i++]='='; 
                }
                else /* c != ' ' */
                {
                  targetbuffer[i++]=c;  
                }
              }
              else /* c != 'e' */
              {
                 targetbuffer[i++]=c;
              }
           }
           else /* c != 'k' */
           {
             targetbuffer[i++]=c;
           }
        }    
        else /* c != 'i' */
        {
          targetbuffer[i++]=c;
        }
      }
      else /* c != 'l' */
      {
        targetbuffer[i++]=c;
      }
    } 
    else /* c != ' ' */
    {
      targetbuffer[i++]=c;
    }
  } /* while loop */

  for (i=0;targetbuffer[i]!='\0';i++)
  {
    c=targetbuffer[i];
    if(c=='=')
    {
      targetbuffer[i]=';';
    }
  }

  tempbuffer=sourcebuffer; /* c=a */
  sourcebuffer=targetbuffer; /* a=b */
  targetbuffer=tempbuffer;  /* b=c */
 
  for (i=0,j=0;sourcebuffer[i]!='\0';i++,j++)
  {
    c=sourcebuffer[i];
    targetbuffer[j]=c;
    if(c==';')
    {
      semicount++;
    }
    if (c=='\n')
    {
      if (semicount < 6)
      {
        for(k=semicount;k<6;k++)
        {
           targetbuffer[j++]=';';
        }      
      }
      semicount=0;
      targetbuffer[j]=c;
    }
  }

  tempbuffer=sourcebuffer; /* c=a */
  sourcebuffer=targetbuffer; /* a=b */
  targetbuffer=tempbuffer;  /* b=c */
 
  for (i=0,j=0;sourcebuffer[i]!='\0';i++,j++)
  {
    if(sourcebuffer[i]==' ')
    {
       if(sourcebuffer[i+1]==';')
       {
         targetbuffer[j]=sourcebuffer[i+1]; 
         i++;
       } 
       else
       {
         targetbuffer[j]=sourcebuffer[i]; 
       }
    }
    else
    {
      targetbuffer[j]=sourcebuffer[i];
    }
  }

  tempbuffer=sourcebuffer; /* c=a */
  sourcebuffer=targetbuffer; /* a=b */
  targetbuffer=tempbuffer;  /* b=c */

  for (i=0,j=0;sourcebuffer[i]!='\0';i++,j++)
  {
    if(sourcebuffer[i]==';')
    {
       targetbuffer[j]=sourcebuffer[i]; 
  
       if(sourcebuffer[i+1]==' ')
       {
         i++;
       } 
    }
    else
    {
      targetbuffer[j]=sourcebuffer[i];
    }
  }
  targetbuffer[j]='\0';

  tempbuffer=sourcebuffer; /* c=a */
  sourcebuffer=targetbuffer; /* a=b */
  targetbuffer=tempbuffer;  /* b=c */

  for (i=0,j=0;sourcebuffer[i]!='\0';i++,j++)
  {
    if(sourcebuffer[i]=='\n')
    {
      i++;
      targetbuffer[j]=sourcebuffer[i];
    }
    else
    {
      targetbuffer[j]=sourcebuffer[i];
    }
  }
  targetbuffer[j]='\0';

  tempbuffer=sourcebuffer; /* c=a */
  sourcebuffer=targetbuffer; /* a=b */
  targetbuffer=tempbuffer;  /* b=c */

  semicount=0;
  targetbuffer[0]='\'';
  for (i=0,j=1;sourcebuffer[i]!='\0';i++,j++)
  {
    if(sourcebuffer[i]==';')
    {
      semicount++;
      targetbuffer[j]='\'';
      targetbuffer[++j]=sourcebuffer[i];
      targetbuffer[++j]='\'';
    }
    else
    {
       targetbuffer[j]=sourcebuffer[i];
    }
  }
  targetbuffer[--j]='\0';

  tempbuffer=sourcebuffer; /* c=a */
  sourcebuffer=targetbuffer; /* a=b */
  targetbuffer=tempbuffer;  /* b=c */
  
  varsarr=malloc( newlinecount * sizeof(*varsarr));

  if (varsarr==NULL)
  {
    fprintf(stderr,"varsarr malloc()\n");
    exit(1);
  }

  token=strtok(sourcebuffer,s);
  for (i=0;i<newlinecount*6;i++)
  {
     if(token==NULL)
     {
        break;
     }
     if (!strcmp(token,"\n"))
     {
       break;
     }
     strcat(varsarr[i].field1,token);     
     printf("var field1 = %s\n",varsarr[i].field1);

     token=strtok(NULL,s);

     if(token==NULL)
     {
        break;
     }
     strcat(varsarr[i].value1,token);     
     printf("var value1 = %s\n",varsarr[i].value1);

     token=strtok(NULL,s);

     if(token==NULL)
     {
        break;
     }
     strcat(varsarr[i].field2,token);     
     printf("var field2 = %s\n",varsarr[i].field2);

     token=strtok(NULL,s);

     if(token==NULL)
     {
        break;
     }
     strcat(varsarr[i].value2,token);     
     printf("var value2 = %s\n",varsarr[i].value2);

     token=strtok(NULL,s);

     if(token==NULL)
     {
        break;
     }
     strcat(varsarr[i].field3,token);     
     printf("var field3 = %s\n",varsarr[i].field3);

     token=strtok(NULL,s);

     if(token==NULL)
     {
        break;
     }
     strcat(varsarr[i].value3,token);     
     printf("var value3 = %s\n",varsarr[i].value3);

     token=strtok(NULL,s);
  }

  free(sourcebuffer);
  free(targetbuffer);
  free(varsarr);

  fclose(fp);

  return 0; 
}

------------------------ end code -------------------------

[toc] | [prev] | [next] | [standalone]


#352023

Fromowl <owl@rooftop.invalid>
Date2016-04-26 20:40 +0000
Message-ID<fhjg030.afji44e@rooftop.invalid>
In reply to#352013
owl <owl@rooftop.invalid> wrote:
> DFS <nospam@dfs.com> wrote:

> 
>> You're not actually writing 3.6M lines to a file, right?
>> 
>  
> 
> Yes.  

For clarification, "Yes" means, "Yes, I am writing 3.6M lines to
a file."

[toc] | [prev] | [next] | [standalone]


#352040

FromDFS <nospam@dfs.com>
Date2016-04-26 17:48 -0400
Message-ID<nfonha$jik$2@dont-email.me>
In reply to#352023
On 4/26/2016 4:40 PM, owl wrote:
> owl <owl@rooftop.invalid> wrote:
>> DFS <nospam@dfs.com> wrote:
>
>>
>>> You're not actually writing 3.6M lines to a file, right?
>>>
>>
>>
>> Yes.
>
> For clarification, "Yes" means, "Yes, I am writing 3.6M lines to
> a file."


I'll try that later in VBScript.  I wouldn't be surprised if it takes 5+ 
minutes.

[toc] | [prev] | [next] | [standalone]


#352045

Fromowl <owl@rooftop.invalid>
Date2016-04-26 22:14 +0000
Message-ID<gjdie95.f@rooftop.invalid>
In reply to#352040
DFS <nospam@dfs.com> wrote:
> On 4/26/2016 4:40 PM, owl wrote:
>> owl <owl@rooftop.invalid> wrote:
>>> DFS <nospam@dfs.com> wrote:
>>
>>>
>>>> You're not actually writing 3.6M lines to a file, right?
>>>>
>>>
>>>
>>> Yes.
>>
>> For clarification, "Yes" means, "Yes, I am writing 3.6M lines to
>> a file."
> 
> 
> I'll try that later in VBScript.  I wouldn't be surprised if it takes 5+ 
> minutes.
> 

My code doesn't actually open and write a file on disk.  It writes
to stdout, and I redirect that to a file on disk.  DOS has a redirect
operator, doesn't it?  YOu should be able to "> output.txt" anything
written to the console.  I can't imagine that would take anywhere near
the time you mentioned earlier.  (6.5 sec or something, was it?).

[toc] | [prev] | [next] | [standalone]


#351576

FromNorman Peelman <npeelman@cfl.rr.com>
Date2016-04-23 23:15 -0400
Message-ID<nfhdi1$isv$1@dont-email.me>
In reply to#351408
On 04/23/2016 12:18 AM, DFS wrote:
> On 4/23/2016 12:09 AM, Norman Peelman wrote:
>
>>    So, (curiosity) what is wrong with it?
>
>
> A bunch of stuff I didn't want to track down and fix.
>
> VBScript has some significant differences from VB/A.
>
> If you develop and test under VBScript you'll see.
>

srArr = Split(srLine,";")
criteria = UBound(srArr) + 1

  ...

if criteria = 1 then
    fld1 = Split(srArr(0),spChar(srArr(0))
end if

if criteria = 2 then
    fld1 = Split(srArr(0),spChar(srArr(0))
    fld2 = Split(srArr(1),spChar(srArr(1))
end if

if criteria = 3 then
    fld1 = Split(srArr{0),spChar(srArr(0))
    fld2 = Split(srArr(1),spChar(srArr(1))
    fld3 = Split(srArr(2),spChar(srArr(2))
end if

...

wscript.echo "'" & Trim(fld1(0)) & "' - '" & Trim(fld1(1)) & "'"
wscript.echo "'" & Trim(fld2(0)) & "' - '" & Trim(fld2(1)) & "'"
wscript.echo "'" & Trim(fld3(0)) & "' - '" & Trim(fld3(1)) & "'"


---or---


srArr = Split(srLine,";")
criteria = UBound(srArr) + 1

...

if criteria > 0 then
    fld1 = Split(srArr(0),spChar(srArr(0))
end if

if criteria > 1 then
    fld2 = Split(srArr(1),spChar(srArr(1))
end if

if criteria > 2 then
    fld3 = Split(srArr(2),spChar(srArr(2))
end if

...

wscript.echo "'" & Trim(fld1(0)) & "' - '" & Trim(fld1(1)) & "'"
wscript.echo "'" & Trim(fld2(0)) & "' - '" & Trim(fld2(1)) & "'"
wscript.echo "'" & Trim(fld3(0)) & "' - '" & Trim(fld3(1)) & "'"


---or---  RegEx


Function parseString()
   Dim StartTime
   Dim SecondsElapsed

   StartTime = Timer

   Dim str
   Dim rgxp As New RegExp
   Dim matches


   With rgxp
     .Global = False
     .pattern = 
"(state){0,1}.*?(=|like){0,1}.*?([A-Z]{2}){0,1}.*?;{0,1}(name){0,1}.*?(=|like){0,1}.*?([a-zA-Z0-9 
]{1,}){0,1}.*?;{0,1}(zip){0,1}(=|like){0,1}.*?([0-9]{5}){0,1}"
   End With

   'str = "state=GA"
   'str = "state=GA;namelikeBurger King"
   str = "state=GA;namelikeBurger King;zip=12345"

   Set matches = rgxp.Execute(str)

   For i = 1 To matches.count
     For j = 1 To matches(i - 1).SubMatches.count
      Debug.Print matches(i - 1).SubMatches(j - 1),
      If (j Mod 3 = 0) Then
        Debug.Print vbCrLf
      End If
     Next j
   Next i

   SecondsElapsed = Round(Timer - StartTime, 2)

   Debug.Print "This code ran successfully in " & SecondsElapsed & " 
seconds"

End Function

---output---

state         =             GA

name          like          Burger King

zip           =             12345

This code ran successfully in 0.01 seconds




First two examples *not tested*.


 >>Thanks, but it won't run in VBSCript.
 >>
 >
 >    So, (curiosity) what is wrong with it?

 >>A bunch of stuff I didn't want to track down and fix.
 >>VBScript has some significant differences from VB/A.
 >>If you develop and test under VBScript you'll see.

   First of all, code <snippet>s corrected above. I was a bit hasty 
trying to do that before running off to work. I also added a second 
option. Second, I was just providing the thought that you were doing an 
unnecessary number of calls to 'Split()'.

   And, what am I missing here? It's absolutely amazing if someone can 
provide an alternative in another language but if it's your VBScript, 
why are there rules?

[toc] | [prev] | [next] | [standalone]


#351577

FromDFS <nospam@dfs.com>
Date2016-04-23 23:30 -0400
Message-ID<nfheeg$kpu$1@dont-email.me>
In reply to#351576
On 4/23/2016 11:15 PM, Norman Peelman wrote:
> On 04/23/2016 12:18 AM, DFS wrote:
>> On 4/23/2016 12:09 AM, Norman Peelman wrote:
>>
>>>    So, (curiosity) what is wrong with it?
>>
>>
>> A bunch of stuff I didn't want to track down and fix.
>>
>> VBScript has some significant differences from VB/A.
>>
>> If you develop and test under VBScript you'll see.
>>
>
> srArr = Split(srLine,";")
> criteria = UBound(srArr) + 1
>
>   ...
>
> if criteria = 1 then
>     fld1 = Split(srArr(0),spChar(srArr(0))
> end if
>
> if criteria = 2 then
>     fld1 = Split(srArr(0),spChar(srArr(0))
>     fld2 = Split(srArr(1),spChar(srArr(1))
> end if
>
> if criteria = 3 then
>     fld1 = Split(srArr{0),spChar(srArr(0))
>     fld2 = Split(srArr(1),spChar(srArr(1))
>     fld3 = Split(srArr(2),spChar(srArr(2))
> end if
>
> ...
>
> wscript.echo "'" & Trim(fld1(0)) & "' - '" & Trim(fld1(1)) & "'"
> wscript.echo "'" & Trim(fld2(0)) & "' - '" & Trim(fld2(1)) & "'"
> wscript.echo "'" & Trim(fld3(0)) & "' - '" & Trim(fld3(1)) & "'"
>
>
> ---or---
>
>
> srArr = Split(srLine,";")
> criteria = UBound(srArr) + 1
>
> ...
>
> if criteria > 0 then
>     fld1 = Split(srArr(0),spChar(srArr(0))
> end if
>
> if criteria > 1 then
>     fld2 = Split(srArr(1),spChar(srArr(1))
> end if
>
> if criteria > 2 then
>     fld3 = Split(srArr(2),spChar(srArr(2))
> end if
>
> ...
>
> wscript.echo "'" & Trim(fld1(0)) & "' - '" & Trim(fld1(1)) & "'"
> wscript.echo "'" & Trim(fld2(0)) & "' - '" & Trim(fld2(1)) & "'"
> wscript.echo "'" & Trim(fld3(0)) & "' - '" & Trim(fld3(1)) & "'"
>
>
> ---or---  RegEx
>
>
> Function parseString()
>    Dim StartTime
>    Dim SecondsElapsed
>
>    StartTime = Timer
>
>    Dim str
>    Dim rgxp As New RegExp
>    Dim matches
>
>
>    With rgxp
>      .Global = False
>      .pattern =
> "(state){0,1}.*?(=|like){0,1}.*?([A-Z]{2}){0,1}.*?;{0,1}(name){0,1}.*?(=|like){0,1}.*?([a-zA-Z0-9
> ]{1,}){0,1}.*?;{0,1}(zip){0,1}(=|like){0,1}.*?([0-9]{5}){0,1}"
>    End With
>
>    'str = "state=GA"
>    'str = "state=GA;namelikeBurger King"
>    str = "state=GA;namelikeBurger King;zip=12345"
>
>    Set matches = rgxp.Execute(str)
>
>    For i = 1 To matches.count
>      For j = 1 To matches(i - 1).SubMatches.count
>       Debug.Print matches(i - 1).SubMatches(j - 1),
>       If (j Mod 3 = 0) Then
>         Debug.Print vbCrLf
>       End If
>      Next j
>    Next i
>
>    SecondsElapsed = Round(Timer - StartTime, 2)
>
>    Debug.Print "This code ran successfully in " & SecondsElapsed & "
> seconds"
>
> End Function
>
> ---output---
>
> state         =             GA
>
> name          like          Burger King
>
> zip           =             12345
>
> This code ran successfully in 0.01 seconds


1000 loops with 6 string parses per loop?

My original did that in 0.156 seconds.





> First two examples *not tested*.

OK.  Then I won't test them, either.



>  >>Thanks, but it won't run in VBSCript.
>  >>
>  >
>  >    So, (curiosity) what is wrong with it?
>
>  >>A bunch of stuff I didn't want to track down and fix.
>  >>VBScript has some significant differences from VB/A.
>  >>If you develop and test under VBScript you'll see.
>
>    First of all, code <snippet>s corrected above. I was a bit hasty
> trying to do that before running off to work. I also added a second
> option. Second, I was just providing the thought that you were doing an
> unnecessary number of calls to 'Split()'.

Maybe.  Your first two examples look nice and tight.

The RegEx thing looks strange, like you hard-coded a few field names. 
In practice, the search looks across: name, street, city, state and zip.



>    And, what am I missing here? It's absolutely amazing if someone can
> provide an alternative in another language but if it's your VBScript,
> why are there rules?

"rules"?  You mean expecting tested code?  Seriously?

[toc] | [prev] | [next] | [standalone]


#351599

FromNorman Peelman <npeelman@cfl.rr.com>
Date2016-04-24 08:52 -0400
Message-ID<nfifce$3jd$1@dont-email.me>
In reply to#351577
On 04/23/2016 11:30 PM, DFS wrote:
> On 4/23/2016 11:15 PM, Norman Peelman wrote:
>> On 04/23/2016 12:18 AM, DFS wrote:
>>> On 4/23/2016 12:09 AM, Norman Peelman wrote:
>>>
>>>>    So, (curiosity) what is wrong with it?
>>>
>>>
>>> A bunch of stuff I didn't want to track down and fix.
>>>
>>> VBScript has some significant differences from VB/A.
>>>
>>> If you develop and test under VBScript you'll see.
>>>
>>

Function parseString3()
   Dim StartTime
   Dim SecondsElapsed

   StartTime = Timer

   Dim srLine, srarr, criteria, fld1, fld2, fld3

   'srLine = "state=GA"
   'srLine = "state=GA;namelikeBurger King"
   srLine = "state=GA;namelikeBurger King;zip=12345"

   srarr = Split(srLine, ";")
   criteria = UBound(srarr) + 1

   If criteria > 0 Then
     fld1 = Split(srarr(0), spChar(srarr(0)))
     Debug.Print "'" & Trim(fld1(0)) & "' - '" & Trim(fld1(1)) & "'"
   End If

   If criteria > 1 Then
     fld2 = Split(srarr(1), spChar(srarr(1)))
     Debug.Print "'" & Trim(fld2(0)) & "' - '" & Trim(fld2(1)) & "'"
   End If

   If criteria > 2 Then
     fld3 = Split(srarr(2), spChar(srarr(2)))
     Debug.Print "'" & Trim(fld3(0)) & "' - '" & Trim(fld3(1)) & "'"
   End If

   SecondsElapsed = Round(Timer - StartTime, 2)
   Debug.Print "This code ran successfully in " & SecondsElapsed & " 
seconds"

End Function

---output---

call parseString3()
'state' - 'GA'
This code ran successfully in 0 seconds

call parseString3()
'state' - 'GA'
'name' - 'Burger King'
This code ran successfully in 0 seconds

call parseString3()
'state' - 'GA'
'name' - 'Burger King'
'zip' - '12345'
This code ran successfully in 0 seconds


>>
>> ---or---  RegEx
>>
>>
>> Function parseString()
>>    Dim StartTime
>>    Dim SecondsElapsed
>>
>>    StartTime = Timer
>>
>>    Dim str
>>    Dim rgxp As New RegExp
>>    Dim matches
>>
>>
>>    With rgxp
>>      .Global = False
>>      .pattern =
>> "(state){0,1}.*?(=|like){0,1}.*?([A-Z]{2}){0,1}.*?;{0,1}(name){0,1}.*?(=|like){0,1}.*?([a-zA-Z0-9
>>
>> ]{1,}){0,1}.*?;{0,1}(zip){0,1}(=|like){0,1}.*?([0-9]{5}){0,1}"
>>    End With
>>
>>    'str = "state=GA"
>>    'str = "state=GA;namelikeBurger King"
>>    str = "state=GA;namelikeBurger King;zip=12345"
>>
>>    Set matches = rgxp.Execute(str)
>>
>>    For i = 1 To matches.count
>>      For j = 1 To matches(i - 1).SubMatches.count
>>       Debug.Print Trim(matches(i - 1).SubMatches(j - 1)),
>>       If (j Mod 3 = 0) Then
>>         Debug.Print vbCrLf
>>       End If
>>      Next j
>>    Next i
>>
>>    SecondsElapsed = Round(Timer - StartTime, 2)
>>
>>    Debug.Print "This code ran successfully in " & SecondsElapsed & "
>> seconds"
>>
>> End Function
>>
>> ---output---
>>
>> state         =             GA
>>
>> name          like          Burger King
>>
>> zip           =             12345
>>
>> This code ran successfully in 0.01 seconds
>
>
> 1000 loops with 6 string parses per loop?
>
> My original did that in 0.156 seconds.
>
>

   What on earth are you talking about?

>
>
>
>> First two examples *not tested*.
>
> OK.  Then I won't test them, either.
>
>
>
>>  >>Thanks, but it won't run in VBSCript.
>>  >>
>>  >
>>  >    So, (curiosity) what is wrong with it?
>>
>>  >>A bunch of stuff I didn't want to track down and fix.
>>  >>VBScript has some significant differences from VB/A.
>>  >>If you develop and test under VBScript you'll see.
>>
>>    First of all, code <snippet>s corrected above. I was a bit hasty
>> trying to do that before running off to work. I also added a second
>> option. Second, I was just providing the thought that you were doing an
>> unnecessary number of calls to 'Split()'.
>
> Maybe.  Your first two examples look nice and tight.
>

  First (fixed & tested) example ran ~0.02 secs, dumped it... fixed (& 
tested) second example. Results above. RegEx fixed - I forgot to Trim() 
the output.


> The RegEx thing looks strange, like you hard-coded a few field names. In
> practice, the search looks across: name, street, city, state and zip.
>

  No fields are hard-coded. To add 'street' and 'city' you would simply 
add them to the regex in the same manner as the others. Order does not 
matter. And that is a horrible regex... could be simplifed (logic would 
stay, just less verbose). I just spelled it out the long way. I also did 
not account for all characters that could be in the 'name' (but easy to 
add to the [a-zA-Z0-9 ] set.

>
>
>>    And, what am I missing here? It's absolutely amazing if someone can
>> provide an alternative in another language but if it's your VBScript,
>> why are there rules?
>
> "rules"?  You mean expecting tested code?  Seriously?
>

   No, I mean stating,

"It's harder than it looks, because the code has to handle 1, 2 or 3 
parts, you have to split on = or like, there's no quotes to keep Burger 
King together, and there can be no leading or trailing spaces when the 
values are stored.  Your code also has to declare at least those 6 
variables."

   Obviously, the regex example does not need those variables. Even the 
first example above doesn't need them all. You come across as though 
you've got the only way to do it.






[toc] | [prev] | [next] | [standalone]


#351602

FromChris Ahlstrom <OFeem1987@teleworm.us>
Date2016-04-24 10:06 -0400
Message-ID<nfijv3$n8p$1@dont-email.me>
In reply to#351599
Norman Peelman wrote this copyrighted missive and expects royalties:

> On 04/23/2016 11:30 PM, DFS wrote:
>>>>
>>>
>
> Function parseString3()
>    Dim StartTime
>    Dim SecondsElapsed
>
>    StartTime = Timer
>
>    Dim srLine, srarr, criteria, fld1, fld2, fld3
>
>    'srLine = "state=GA"
>    'srLine = "state=GA;namelikeBurger King"
>    srLine = "state=GA;namelikeBurger King;zip=12345"

That's the correct job for DFS, but the wrong zip code :-D

-- 
You love your home and want it to be beautiful.

[toc] | [prev] | [next] | [standalone]


#351627

FromFabian Russell <fb@zen.info>
Date2016-04-24 15:59 +0000
Message-ID<nfiqh41lko@news3.newsguy.com>
In reply to#351602
On Sun, 24 Apr 2016 10:06:34 -0400, Chris Ahlstrom wrote:

>>    srLine = "state=GA;namelikeBurger King;zip=12345"
> 
> That's the correct job for DFS,
>

Nah.  The POS at Burger King uses a Linux back-end,
and the Dumb Fuck would be too stupid to master the
interface.

[toc] | [prev] | [next] | [standalone]


#351656

FromNorman Peelman <npeelman@cfl.rr.com>
Date2016-04-24 15:45 -0400
Message-ID<nfj7ig$qtd$1@dont-email.me>
In reply to#351577
   Just FYI, I dumped the regex example... it has some faults and I 
don't know enough about regex to fix it. I'm sure it could be fixed but 
actually this example (from previous post) is the fastest.


Function parseString3()
   Dim StartTime
   Dim SecondsElapsed

   StartTime = Timer

   Dim srLine, srarr, criteria, fld1, fld2, fld3

   'srLine = "state=GA"
   'srLine = "state=GA;namelikeBurger King"
   srLine = "state=GA;namelikeBurger King;zip=12345"

   srarr = Split(srLine, ";")
   criteria = UBound(srarr) + 1

   If criteria > 0 Then
     fld1 = Split(srarr(0), spChar(srarr(0)))
     Debug.Print "'" & Trim(fld1(0)) & "' - '" & Trim(fld1(1)) & "'"
   End If

   If criteria > 1 Then
     fld2 = Split(srarr(1), spChar(srarr(1)))
     Debug.Print "'" & Trim(fld2(0)) & "' - '" & Trim(fld2(1)) & "'"
   End If

   If criteria > 2 Then
     fld3 = Split(srarr(2), spChar(srarr(2)))
     Debug.Print "'" & Trim(fld3(0)) & "' - '" & Trim(fld3(1)) & "'"
   End If

   SecondsElapsed = Round(Timer - StartTime, 2)
   Debug.Print "This code ran successfully in " & SecondsElapsed & " 
seconds"

End Function

---output---

call parseString3()
'state' - 'GA'
This code ran successfully in 0 seconds

call parseString3()
'state' - 'GA'
'name' - 'Burger King'
This code ran successfully in 0 seconds

call parseString3()
'state' - 'GA'
'name' - 'Burger King'
'zip' - '12345'
This code ran successfully in 0 seconds

[toc] | [prev] | [next] | [standalone]


#351762

FromDFS <nospam@dfs.com>
Date2016-04-25 10:19 -0400
Message-ID<nfl8s3$avp$1@dont-email.me>
In reply to#351656
On 4/24/2016 3:45 PM, Norman Peelman wrote:
>    Just FYI, I dumped the regex example... it has some faults and I
> don't know enough about regex to fix it. I'm sure it could be fixed but
> actually this example (from previous post) is the fastest.
>
>
> Function parseString3()
>    Dim StartTime
>    Dim SecondsElapsed
>
>    StartTime = Timer
>
>    Dim srLine, srarr, criteria, fld1, fld2, fld3
>
>    'srLine = "state=GA"
>    'srLine = "state=GA;namelikeBurger King"
>    srLine = "state=GA;namelikeBurger King;zip=12345"
>
>    srarr = Split(srLine, ";")
>    criteria = UBound(srarr) + 1
>
>    If criteria > 0 Then
>      fld1 = Split(srarr(0), spChar(srarr(0)))
>      Debug.Print "'" & Trim(fld1(0)) & "' - '" & Trim(fld1(1)) & "'"
>    End If
>
>    If criteria > 1 Then
>      fld2 = Split(srarr(1), spChar(srarr(1)))
>      Debug.Print "'" & Trim(fld2(0)) & "' - '" & Trim(fld2(1)) & "'"
>    End If
>
>    If criteria > 2 Then
>      fld3 = Split(srarr(2), spChar(srarr(2)))
>      Debug.Print "'" & Trim(fld3(0)) & "' - '" & Trim(fld3(1)) & "'"
>    End If
>
>    SecondsElapsed = Round(Timer - StartTime, 2)
>    Debug.Print "This code ran successfully in " & SecondsElapsed & "
> seconds"
>
> End Function


Looks good, but it doesn't assign values to variables val1,val2,val3

Also appears to not handle string splitting on = or like (or do you also 
use my spChar() function but didn't show it?)






> ---output---
>
> call parseString3()
> 'state' - 'GA'
> This code ran successfully in 0 seconds
>
> call parseString3()
> 'state' - 'GA'
> 'name' - 'Burger King'
> This code ran successfully in 0 seconds
>
> call parseString3()
> 'state' - 'GA'
> 'name' - 'Burger King'
> 'zip' - '12345'
> This code ran successfully in 0 seconds


Time for one parse is meaningless.  We (owl and I) have been timing 6000 
parses.

My VBS does it in 0.156 seconds.  His C program was 0.048 sec.


[toc] | [prev] | [next] | [standalone]


#351863

FromNorman Peelman <npeelman@cfl.rr.com>
Date2016-04-25 20:26 -0400
Message-ID<nfmccp$p21$1@dont-email.me>
In reply to#351762
On 04/25/2016 10:19 AM, DFS wrote:
> On 4/24/2016 3:45 PM, Norman Peelman wrote:
>>    Just FYI, I dumped the regex example... it has some faults and I
>> don't know enough about regex to fix it. I'm sure it could be fixed but
>> actually this example (from previous post) is the fastest.
>>
>>
>> Function parseString3()
>>    Dim StartTime
>>    Dim SecondsElapsed
>>
>>    StartTime = Timer
>>
>>    Dim srLine, srarr, criteria, fld1, fld2, fld3
>>
>>    'srLine = "state=GA"
>>    'srLine = "state=GA;namelikeBurger King"
>>    srLine = "state=GA;namelikeBurger King;zip=12345"
>>
>>    srarr = Split(srLine, ";")
>>    criteria = UBound(srarr) + 1
>>
>>    If criteria > 0 Then
>>      fld1 = Split(srarr(0), spChar(srarr(0)))
>>      Debug.Print "'" & Trim(fld1(0)) & "' - '" & Trim(fld1(1)) & "'"
>>    End If
>>
>>    If criteria > 1 Then
>>      fld2 = Split(srarr(1), spChar(srarr(1)))
>>      Debug.Print "'" & Trim(fld2(0)) & "' - '" & Trim(fld2(1)) & "'"
>>    End If
>>
>>    If criteria > 2 Then
>>      fld3 = Split(srarr(2), spChar(srarr(2)))
>>      Debug.Print "'" & Trim(fld3(0)) & "' - '" & Trim(fld3(1)) & "'"
>>    End If
>>
>>    SecondsElapsed = Round(Timer - StartTime, 2)
>>    Debug.Print "This code ran successfully in " & SecondsElapsed & "
>> seconds"
>>
>> End Function
>
>
> Looks good, but it doesn't assign values to variables val1,val2,val3
>
> Also appears to not handle string splitting on = or like (or do you also
> use my spChar() function but didn't show it?)
>
>

   Why must those variables be used? The Split function returns an array 
so instead of 'fld1' and 'val1' you have 'fld1(0)' and 'fld1(1)'. One 
call, not two. Your 'spChar()' is used right there in the code shown. I 
only output it in the same format as you suggested for 'testing' in you 
original post.


Changing the output to:

Debug.Print Trim(fld1(0)) & " " & spChar(srarr(0)) & " " & Trim(fld1(1))

accordingly, shows:


call parseString3()
state = GA
name like Burger King
zip = 12345
This code ran successfully in 0 seconds.

   I'm assuming that means that it run in under .01 seconds.

>
>> ---output---
>>
>> call parseString3()
>> 'state' - 'GA'
>> This code ran successfully in 0 seconds
>>
>> call parseString3()
>> 'state' - 'GA'
>> 'name' - 'Burger King'
>> This code ran successfully in 0 seconds
>>
>> call parseString3()
>> 'state' - 'GA'
>> 'name' - 'Burger King'
>> 'zip' - '12345'
>> This code ran successfully in 0 seconds
>
>
> Time for one parse is meaningless.  We (owl and I) have been timing 6000
> parses.
>
> My VBS does it in 0.156 seconds.  His C program was 0.048 sec.
>


VBScript                      C(owl)
--------                      ------
1 parse per .000026 seconds   1 parse per .000008



Parses   VBScript Time  C Time (owl)
------   -------------  ------------
6000     0.156 secs     0.048 secs
1000000     26 secs         8 secs


   Not to be rude but although I have been scanning the thread, I really 
feel like the goal post keeps moving. You really didn't provide enough 
information at the start.

  Also, understand again... I'm doing this in VBA - so you have to 
factor in that I am dumping output to the 'Immediate Window' (in Access) 
which has inherent performance costs. At the end of the day, there are 
several options to choose from. I can tell you now that as far as the VB 
goes, my version of the core logic will be faster than yours (original) 
by default. It performs only a third of the function calls your does. 
What you want to do with the output and how you want it formatted is 
your business.

   I haven't see owls source, but it would be nice. I do believe he 
mentioned that the lowest times attained were from *not* outputting 
anything to the screen. I would suggest that that be the case. Also, I 
don't know if it's really fair to have disk IO in the mix either. Not to 
mention that I'm still not sure you have revealed the true 
input-through-output desired. 'parseString(srLine)' seems to me to mean 
"feed it one line at a time". You never mentioned running 1000s of 
parses. I believe someone just *did* it and it became part of the request.




[toc] | [prev] | [next] | [standalone]


#351890

FromDFS <nospam@dfs.com>
Date2016-04-25 23:24 -0400
Message-ID<nfmmqn$hkk$1@dont-email.me>
In reply to#351863
On 4/25/2016 8:26 PM, Norman Peelman wrote:
> On 04/25/2016 10:19 AM, DFS wrote:
>> On 4/24/2016 3:45 PM, Norman Peelman wrote:
>>>    Just FYI, I dumped the regex example... it has some faults and I
>>> don't know enough about regex to fix it. I'm sure it could be fixed but
>>> actually this example (from previous post) is the fastest.
>>>
>>>
>>> Function parseString3()
>>>    Dim StartTime
>>>    Dim SecondsElapsed
>>>
>>>    StartTime = Timer
>>>
>>>    Dim srLine, srarr, criteria, fld1, fld2, fld3
>>>
>>>    'srLine = "state=GA"
>>>    'srLine = "state=GA;namelikeBurger King"
>>>    srLine = "state=GA;namelikeBurger King;zip=12345"
>>>
>>>    srarr = Split(srLine, ";")
>>>    criteria = UBound(srarr) + 1
>>>
>>>    If criteria > 0 Then
>>>      fld1 = Split(srarr(0), spChar(srarr(0)))
>>>      Debug.Print "'" & Trim(fld1(0)) & "' - '" & Trim(fld1(1)) & "'"
>>>    End If
>>>
>>>    If criteria > 1 Then
>>>      fld2 = Split(srarr(1), spChar(srarr(1)))
>>>      Debug.Print "'" & Trim(fld2(0)) & "' - '" & Trim(fld2(1)) & "'"
>>>    End If
>>>
>>>    If criteria > 2 Then
>>>      fld3 = Split(srarr(2), spChar(srarr(2)))
>>>      Debug.Print "'" & Trim(fld3(0)) & "' - '" & Trim(fld3(1)) & "'"
>>>    End If
>>>
>>>    SecondsElapsed = Round(Timer - StartTime, 2)
>>>    Debug.Print "This code ran successfully in " & SecondsElapsed & "
>>> seconds"
>>>
>>> End Function
>>
>>
>> Looks good, but it doesn't assign values to variables val1,val2,val3
>>
>> Also appears to not handle string splitting on = or like (or do you also
>> use my spChar() function but didn't show it?)
>>
>>
>
>    Why must those variables be used?


Because that's what I specified in the first sentence in the first post 
in this thread.  Your code isn't close to doing that, yet.  Easy enough 
to fix:

Dim splitter, val1
If criteria > 0 Then
    splitter = Split(srarr(0), spChar(srarr(0)))
    fld1 = Trim(splitter(0))
    val1 = Trim(splitter(1))
End If

If I do that, it runs in 0.141 sec for 6000 parses.  (see code at bottom)



> The Split function returns an array
> so instead of 'fld1' and 'val1' you have 'fld1(0)' and 'fld1(1)'. One
> call, not two. Your 'spChar()' is used right there in the code shown. I
> only output it in the same format as you suggested for 'testing' in you
> original post.
>
>
> Changing the output to:
>
> Debug.Print Trim(fld1(0)) & " " & spChar(srarr(0)) & " " & Trim(fld1(1))
>
> accordingly, shows:
>
>
> call parseString3()
> state = GA
> name like Burger King
> zip = 12345
> This code ran successfully in 0 seconds.
>
>    I'm assuming that means that it run in under .01 seconds.
>
>>
>>> ---output---
>>>
>>> call parseString3()
>>> 'state' - 'GA'
>>> This code ran successfully in 0 seconds
>>>
>>> call parseString3()
>>> 'state' - 'GA'
>>> 'name' - 'Burger King'
>>> This code ran successfully in 0 seconds
>>>
>>> call parseString3()
>>> 'state' - 'GA'
>>> 'name' - 'Burger King'
>>> 'zip' - '12345'
>>> This code ran successfully in 0 seconds
>>
>>
>> Time for one parse is meaningless.  We (owl and I) have been timing 6000
>> parses.
>>
>> My VBS does it in 0.156 seconds.  His C program was 0.048 sec.
>>
>
>
> VBScript                      C(owl)
> --------                      ------
> 1 parse per .000026 seconds   1 parse per .000008
>
>
>
> Parses   VBScript Time  C Time (owl)
> ------   -------------  ------------
> 6000     0.156 secs     0.048 secs
> 1000000     26 secs         8 secs
>
>
>    Not to be rude but although I have been scanning the thread, I really
> feel like the goal post keeps moving. You really didn't provide enough
> information at the start.

Go back and read the 1st post again.  I provided more than enough info 
to complete the challenge.

You kept posting untested VBA and wanting me to test it.  But I may have 
complicated it by talking about 6000 parses, timing, etc.  So thanks for 
hanging in the thread.


>   Also, understand again... I'm doing this in VBA - so you have to
> factor in that I am dumping output to the 'Immediate Window' (in Access)
> which has inherent performance costs.

No need to print to screen, except to make sure the variables hold the 
right data after the parse.  One timer for all 6000 parses is all you need.

I tried your [slightly modified] code in VBA Access 2003 for 6000 parses 
and it ran in 0.141 secs, so slightly faster than my VBS which was 0.156.


> At the end of the day, there are
> several options to choose from. I can tell you now that as far as the VB
> goes, my version of the core logic will be faster than yours (original)
> by default. It performs only a third of the function calls your does.
> What you want to do with the output and how you want it formatted is
> your business.

Your 'core logic' is faulty.  It doesn't Dim or assign 3 of the 6 
variables required.  I fixed that below.



>    I haven't see owls source, but it would be nice. I do believe he
> mentioned that the lowest times attained were from *not* outputting
> anything to the screen. I would suggest that that be the case. Also, I
> don't know if it's really fair to have disk IO in the mix either.

Disk IO not required.  If I write a 6-line file 1000x, my original VBS 
code executes in 6.551 seconds.  Without the file writes, it's 0.156.


> Not to
> mention that I'm still not sure you have revealed the true
> input-through-output desired. 'parseString(srLine)' seems to me to mean
> "feed it one line at a time". You never mentioned running 1000s of
> parses. I believe someone just *did* it and it became part of the request.

Yes to all that.  It takes one line at a time.  I didn't time it at 
first, and I never requested thousands of parses - owl timed his for 
1000 loops using 6 strings per loop, so I did that as a performance 
check, and I requested you do it, too, for comparison sake.

Thanks for looking at this.  It's fun and challenging for the whole family!



=======================================================================
Full code in Access 2003 VBA (Norman original, DFS mods
=======================================================================
call testNP(1000)
0.141

----------------------------------------------------

Public Sub testNP(loops As Integer)
  Dim i, StartTime
  StartTime = Timer

  For i = 1 To loops
   parseStringNP ("name like *pizza")
   parseStringNP ("name like *pizza ;zip=30303")
   parseStringNP ("name like *pizza ;zip=30303;street like *Buford Hwy")

   parseStringNP ("state=GA")
   parseStringNP ("state=GA;name=Burger King")
   parseStringNP ("state=GA;name=Burger King;ziplike303*")
  Next i

  Debug.Print Round(Timer - StartTime, 3)
End Sub

----------------------------------------------------

Sub parseStringNP(srLine As String)

    Dim srarr, criteria
    Dim splitter, fld1, fld2, fld3, val1, val2, val3

    srarr = split(srLine, ";")
    criteria = UBound(srarr) + 1

    If criteria > 0 Then
      splitter = Split(srarr(0), spChar(srarr(0)))
      fld1 = Trim(splitter(0))
      val1 = Trim(splitter(1))
    End If

    If criteria > 1 Then
      splitter = Split(srarr(1), spChar(srarr(1)))
      fld2 = Trim(splitter(0))
      val2 = Trim(splitter(1))
    End If

    If criteria > 2 Then
      splitter = Split(srarr(2), spChar(srarr(2)))
      fld3 = Trim(splitter(0))
      val3 = Trim(splitter(1))
    End If

    'Debug.Print "'" & fld1 & "' - '" & val1 & "'"
    'Debug.Print "'" & fld2 & "' - '" & val2 & "'"
    'Debug.Print "'" & fld3 & "' - '" & val3 & "'"
    'Debug.Print "---------------------"

End Sub

----------------------------------------------------

Function spChar(lineToSplit As Variant) As String

   spChar = "="
   If InStr(lineToSplit, "like") > 0 Then spChar = "like"

End Function

=======================================================================

So that's 19 lines of 'core split/assign logic'  (2 lines shorter than 
my original VBS), and a bit faster.

In perl it can be done in 2-5 lines, and runs around 50% faster.

[toc] | [prev] | [next] | [standalone]


#351906

Fromowl <owl@rooftop.invalid>
Date2016-04-26 05:03 +0000
Message-ID<thug03a43ww.8r3@rooftop.invalid>
In reply to#351890
DFS <nospam@dfs.com> wrote:
> On 4/25/2016 8:26 PM, Norman Peelman wrote:

...
> 
>>    I haven't see owls source, but it would be nice. I do believe he
>> mentioned that the lowest times attained were from *not* outputting
>> anything to the screen. I would suggest that that be the case. Also, I
>> don't know if it's really fair to have disk IO in the mix either.
> 
> Disk IO not required.  If I write a 6-line file 1000x, my original VBS 
> code executes in 6.551 seconds.  Without the file writes, it's 0.156.
> 

Realistically, any program like this probably going to get its input
from a file and write its output to a file.

[toc] | [prev] | [next] | [standalone]


#351961

FromDFS <nospam@dfs.com>
Date2016-04-26 11:40 -0400
Message-ID<nfo1u3$t9f$1@dont-email.me>
In reply to#351906
On 4/26/2016 1:03 AM, owl wrote:
> DFS <nospam@dfs.com> wrote:
>> On 4/25/2016 8:26 PM, Norman Peelman wrote:
>
> ...
>>
>>>     I haven't see owls source, but it would be nice. I do believe he
>>> mentioned that the lowest times attained were from *not* outputting
>>> anything to the screen. I would suggest that that be the case. Also, I
>>> don't know if it's really fair to have disk IO in the mix either.
>>
>> Disk IO not required.  If I write a 6-line file 1000x, my original VBS
>> code executes in 6.551 seconds.  Without the file writes, it's 0.156.
>>
>
> Realistically, any program like this probably going to get its input
> from a file and write its output to a file.


Sure, but this parse is a small part of a much larger program.

[toc] | [prev] | [next] | [standalone]


#351768

FromSandman <mr@sandman.net>
Date2016-04-25 15:14 +0000
Message-ID<sandman-061f8c169bbdb2e75bbf17840d48d7ec@individual.net>
In reply to#350996
In article <nf87hq$ndh$1@dont-email.me>, DFS wrote:

> Parse a search string composed of 1, 2 or 3 parts, separated by a 
> semicolon, into 2, 4 or 6 variables (field1, value1, etc)

> use 1 part : state=GA
> use 2 parts: state=GA ; name = Burger King
> use 3 parts: state=GA ; name = Burger King ; zip like 303*

> The goal is to split it up like this:

>   var field1 = 'state'
> var value1 = 'GA'
> other vars empty

>   var field1 = 'state'
> var value1 = 'GA'
> var field2 = 'name'
> var value2 = 'Burger King'
> other vars empty

>   var field1 = 'state'
> var value1 = 'GA'
> var field2 = 'name'
> var value2 = 'Burger King'
> var field3 = 'zip'
> var value3 = '303*'

Seems cumbersome, where is this input coming from? I'll feed it from the 
command line. here's my PHP script:

foreach (preg_split("/\s*;\s*/", join("", array_slice($argv, 1))) as $part){
  list ($field, $qualifier, $value) = preg_split("/\s*(=|like)\s*/", $part, 
0, PREG_SPLIT_DELIM_CAPTURE);
  print "'$field' $qualifier '$value'\n";
}

Here's me using it:

/parse.php "state=GA ; name = Burger King ; zip like 303*"
'state' = 'GA'
'name' = 'Burger King'
'zip' like '303*'

Obviously putting them in named variables is a piece of cake:

foreach (preg_split("/\s*;\s*/", join("", array_slice($argv, 1))) as $part){
	list ($field, $qualifier, $value) = preg_split("/\s*(=|like)\s*/", 
$part, 0, PREG_SPLIT_DELIM_CAPTURE);
	$nr++;
	$output[] = ["field" . $nr => $field, "value" . $nr => $value];
}
print_r($output);

Output:

/parse.php "state=GA ; name = Burger King ; zip like 303*"
Array
(
    [0] => Array
        (
            [field1] => state
            [value1] => GA
        )

    [1] => Array
        (
            [field2] => name
            [value2] => Burger King
        )

    [2] => Array
        (
            [field3] => zip
            [value3] => 303*
        )

)

Only, you lose the qualifiers (i.e. you don't get the "=" or "like" which is 
supposedly meaningful. 

-- 
Sandman

[toc] | [prev] | [next] | [standalone]


Page 3 of 7 — ← Prev page 1 2 [3] 4 5 6 7  Next page →

Back to top | Article view | comp.os.linux.advocacy


csiph-web