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 1 of 7  [1] 2 3 4 5 6 7  Next page →


#350996 — A maybe interesting code challenge

FromDFS <nospam@dfs.com>
Date2016-04-20 11:37 -0400
SubjectA maybe interesting code challenge
Message-ID<nf87hq$ndh$1@dont-email.me>
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.

[toc] | [next] | [standalone]


#351000

FromSteve Carroll <fretwizzer@gmail.com>
Date2016-04-20 08:45 -0700
Message-ID<53055ce2-1df3-4a84-b83f-e6483f0a30f9@googlegroups.com>
In reply to#350996
On Wednesday, April 20, 2016 at 9:37:44 AM UTC-6, 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*

I can see for the state and zip but, in any given, random string, how would you be able to exactly determine what the name is? Is this related to your previous stuff where the name consists of everything minus the other bits of data (then it makes sense)?
 
> If someone posts a 2-line perl solution, I'm hurling.

Hehe ;)

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


#351005

FromDFS <nospam@dfs.com>
Date2016-04-20 11:57 -0400
Message-ID<nf88nm$rrv$1@dont-email.me>
In reply to#351000
On 4/20/2016 11:45 AM, Steve Carroll wrote:
> On Wednesday, April 20, 2016 at 9:37:44 AM UTC-6, 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*
>
> I can see for the state and zip but, in any given, random string, how
> would you be able to exactly determine what the name is? Is this
> related to your previous stuff where the name consists of everything
> minus the other bits of data (then it makes sense)?


wildcards.  The search routine is almost infinitely variable.

city = Atlanta
state=TN ; name like Burger* ; street like Main*
state=GA ; name like *pizza ; zip = 30017

all are valid inputs

This parser is part of a real VBScript program I'm writing to replace 
Fabian Russell at his Windows job.



>> If someone posts a 2-line perl solution, I'm hurling.
>
> Hehe ;)


It makes sense for perl to be shorter, but to be 1/3 the lines and run
in (maybe) 1/10th the time is kind of embarrassing for VB.  I say maybe 
because I haven't run Sandman's script on my own Linux system yet.



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


#351008

FromSteve Carroll <fretwizzer@gmail.com>
Date2016-04-20 09:02 -0700
Message-ID<f7a7cfa3-4d3f-4f9f-bcc2-56701823d117@googlegroups.com>
In reply to#351005
On Wednesday, April 20, 2016 at 9:57:56 AM UTC-6, DFS wrote:
> On 4/20/2016 11:45 AM, Steve Carroll wrote:
> > On Wednesday, April 20, 2016 at 9:37:44 AM UTC-6, 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*
> >
> > I can see for the state and zip but, in any given, random string, how
> > would you be able to exactly determine what the name is? Is this
> > related to your previous stuff where the name consists of everything
> > minus the other bits of data (then it makes sense)?
> 
> 
> wildcards.  The search routine is almost infinitely variable.
> 
> city = Atlanta
> state=TN ; name like Burger* ; street like Main*
> state=GA ; name like *pizza ; zip = 30017
> 
> all are valid inputs
> 
> This parser is part of a real VBScript program I'm writing to replace 
> Fabian Russell at his Windows job.
> 
> 
> 
> >> If someone posts a 2-line perl solution, I'm hurling.
> >
> > Hehe ;)
> 
> 
> It makes sense for perl to be shorter, but to be 1/3 the lines and run
> in (maybe) 1/10th the time is kind of embarrassing for VB.  I say maybe 
> because I haven't run Sandman's script on my own Linux system yet.

The guy has a seriously cool CMS (written from scratch in PHP) so he has some programming experience. 

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


#351098

Fromowl <owl@rooftop.invalid>
Date2016-04-21 01:54 +0000
Message-ID<thjgu0a.af@rooftop.invalid>
In reply to#351005
DFS <nospam@dfs.com> wrote:
> On 4/20/2016 11:45 AM, Steve Carroll wrote:
>> On Wednesday, April 20, 2016 at 9:37:44 AM UTC-6, 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*
>>
>> I can see for the state and zip but, in any given, random string, how
>> would you be able to exactly determine what the name is? Is this
>> related to your previous stuff where the name consists of everything
>> minus the other bits of data (then it makes sense)?
> 
> 
> wildcards.  The search routine is almost infinitely variable.
> 
> city = Atlanta
> state=TN ; name like Burger* ; street like Main*
> state=GA ; name like *pizza ; zip = 30017
> 
> all are valid inputs
> 
> This parser is part of a real VBScript program I'm writing to replace 
> Fabian Russell at his Windows job.
> 
> 
> 
>>> If someone posts a 2-line perl solution, I'm hurling.
>>
>> Hehe ;)
> 
> 
> It makes sense for perl to be shorter, but to be 1/3 the lines and run
> in (maybe) 1/10th the time is kind of embarrassing for VB.  I say maybe 
> because I haven't run Sandman's script on my own Linux system yet.
> 
> 

This one's fairly slow: times between 0.07 sec and 0.09 sec
just for these few lines.

anon@lowtide:~/code/dfs/nah$ cat input
state=GA 
state=GA ; name = Burger King
state=GA ; name = Burger King ; zip like 303* 
city = Atlanta
state=TN ; name like Burger* ; street like Main*
state=GA ; name like *pizza ; zip = 30017
anon@lowtide:~/code/dfs/nah$ 
anon@lowtide:~/code/dfs/nah$ ./vars input
var field1 = 'state'
var value1 = 'GA'
var field2 = 
var value2 = 
var field3 = 
var value3 = 
-----
var field1 = 'state'
var value1 = 'GA'
var field2 = 'name'
var value2 = 'BurgerKing'
var field3 = 
var value3 = 
-----
var field1 = 'state'
var value1 = 'GA'
var field2 = 'name'
var value2 = 'BurgerKing'
var field3 = 'zip'
var value3 = '303*'
-----
var field1 = 'city'
var value1 = 'Atlanta'
var field2 = 
var value2 = 
var field3 = 
var value3 = 
-----
var field1 = 'state'
var value1 = 'TN'
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$ 
anon@lowtide:~/code/dfs/nah$ cat vars
#!/bin/bash
echo "var field1 = " > labels
echo "var value1 = " >> labels
echo "var field2 = " >> labels
echo "var value2 = " >> labels
echo "var field3 = " >> labels
echo "var value3 = " >> labels
sed -e 's/$/;/g' ${1} | csplit -s -z - /\;/ {*}
sed -i 's/;/\n/g' xx*
sed -i 's/like/=/g' xx*
sed -i 's/ //g' xx*
sed -i 's/=/\n/g' xx*
sed -i 's/\(.*=\)\(.*\)/\2/g' xx*
sed -i '/^$/d' xx*
sed -i '/^\s$/d' xx*
sed -i "s/^/\\'/g" xx*
sed -i "s/$/\\'/g" xx*
for i in xx*;do paste labels ${i}>labels${i};echo "-----">>labels${i};done
cat labelsxx* | sed -e 's/\t//g'
rm xx*
rm labels*
anon@lowtide:~/code/dfs/nah$ 

 

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


#351102

FromSteve Carroll <fretwizzen@gmail.com>
Date2016-04-20 18:57 -0700
Message-ID<ebe9918e-9788-43ae-bbeb-958653d1e146@googlegroups.com>
In reply to#351098
On Thursday, April 21, 2016 at 1:54:14 AM UTC, owl wrote:
> DFS <nospam@dfs.com> wrote:
> > On 4/20/2016 11:45 AM, Steve Carroll wrote:
> >> On Wednesday, April 20, 2016 at 9:37:44 AM UTC-6, 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*
> >>
> >> I can see for the state and zip but, in any given, random string, how
> >> would you be able to exactly determine what the name is? Is this
> >> related to your previous stuff where the name consists of everything
> >> minus the other bits of data (then it makes sense)?
> > 
> > 
> > wildcards.  The search routine is almost infinitely variable.
> > 
> > city = Atlanta
> > state=TN ; name like Burger* ; street like Main*
> > state=GA ; name like *pizza ; zip = 30017
> > 
> > all are valid inputs
> > 
> > This parser is part of a real VBScript program I'm writing to replace 
> > Fabian Russell at his Windows job.
> > 
> > 
> > 
> >>> If someone posts a 2-line perl solution, I'm hurling.
> >>
> >> Hehe ;)
> > 
> > 
> > It makes sense for perl to be shorter, but to be 1/3 the lines and run
> > in (maybe) 1/10th the time is kind of embarrassing for VB.  I say maybe 
> > because I haven't run Sandman's script on my own Linux system yet.
> > 
> > 
> 
> This one's fairly slow: times between 0.07 sec and 0.09 sec
> just for these few lines.
> 
> anon@lowtide:~/code/dfs/nah$ cat input
> state=GA 
> state=GA ; name = Burger King
> state=GA ; name = Burger King ; zip like 303* 
> city = Atlanta
> state=TN ; name like Burger* ; street like Main*
> state=GA ; name like *pizza ; zip = 30017
> anon@lowtide:~/code/dfs/nah$ 
> anon@lowtide:~/code/dfs/nah$ ./vars input
> var field1 = 'state'
> var value1 = 'GA'
> var field2 = 
> var value2 = 
> var field3 = 
> var value3 = 
> -----
> var field1 = 'state'
> var value1 = 'GA'
> var field2 = 'name'
> var value2 = 'BurgerKing'
> var field3 = 
> var value3 = 
> -----
> var field1 = 'state'
> var value1 = 'GA'
> var field2 = 'name'
> var value2 = 'BurgerKing'
> var field3 = 'zip'
> var value3 = '303*'
> -----
> var field1 = 'city'
> var value1 = 'Atlanta'
> var field2 = 
> var value2 = 
> var field3 = 
> var value3 = 
> -----
> var field1 = 'state'
> var value1 = 'TN'
> 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$ 
> anon@lowtide:~/code/dfs/nah$ cat vars
> #!/bin/bash
> echo "var field1 = " > labels
> echo "var value1 = " >> labels
> echo "var field2 = " >> labels
> echo "var value2 = " >> labels
> echo "var field3 = " >> labels
> echo "var value3 = " >> labels
> sed -e 's/$/;/g' ${1} | csplit -s -z - /\;/ {*}
> sed -i 's/;/\n/g' xx*
> sed -i 's/like/=/g' xx*
> sed -i 's/ //g' xx*
> sed -i 's/=/\n/g' xx*
> sed -i 's/\(.*=\)\(.*\)/\2/g' xx*
> sed -i '/^$/d' xx*
> sed -i '/^\s$/d' xx*
> sed -i "s/^/\\'/g" xx*
> sed -i "s/$/\\'/g" xx*
> for i in xx*;do paste labels ${i}>labels${i};echo "-----">>labels${i};done
> cat labelsxx* | sed -e 's/\t//g'
> rm xx*
> rm labels*
> anon@lowtide:~/code/dfs/nah$

Where is Snit to show off how fast OS X is?

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


#351107

Fromowl <owl@rooftop.invalid>
Date2016-04-21 02:45 +0000
Message-ID<xgo3a0ap.4@rooftop.invalid>
In reply to#351098
owl <owl@rooftop.invalid> wrote:
> DFS <nospam@dfs.com> wrote:
...
>> 
>> It makes sense for perl to be shorter, but to be 1/3 the lines and run
>> in (maybe) 1/10th the time is kind of embarrassing for VB.  I say maybe 
>> because I haven't run Sandman's script on my own Linux system yet.
>> 
>> 
> 
> This one's fairly slow: times between 0.07 sec and 0.09 sec
> just for these few lines.
> 
...

Terrible.  Approximately 30 sec for 6000 records.  All those
csplit tempfiles are expensive.  Have to try a different approach.

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


#351108

FromDFS <nospam@dfs.com>
Date2016-04-20 23:01 -0400
Message-ID<nf9fjm$4gn$1@dont-email.me>
In reply to#351107
On 4/20/2016 10:45 PM, owl wrote:
> owl <owl@rooftop.invalid> wrote:
>> DFS <nospam@dfs.com> wrote:
> ...
>>>
>>> It makes sense for perl to be shorter, but to be 1/3 the lines and run
>>> in (maybe) 1/10th the time is kind of embarrassing for VB.  I say maybe
>>> because I haven't run Sandman's script on my own Linux system yet.
>>>
>>>
>>
>> This one's fairly slow: times between 0.07 sec and 0.09 sec
>> just for these few lines.
>>
> ...
>
> Terrible.  Approximately 30 sec for 6000 records.  All those
> csplit tempfiles are expensive.  Have to try a different approach.


Very slow - you're off your game.

4.39 sec for 1000 loops with my VB code.

If I remove the 4 screen Echo statements, it's 0.17 seconds to parse 
6000 strings.

VB FTFW!  Finally!



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


#351112

Fromowl <owl@rooftop.invalid>
Date2016-04-21 03:56 +0000
Message-ID<hjlkgas0.a3@rooftop.invalid>
In reply to#351108
DFS <nospam@dfs.com> wrote:
> On 4/20/2016 10:45 PM, owl wrote:
>> owl <owl@rooftop.invalid> wrote:
>>> DFS <nospam@dfs.com> wrote:
>> ...
>>>>
>>>> It makes sense for perl to be shorter, but to be 1/3 the lines and run
>>>> in (maybe) 1/10th the time is kind of embarrassing for VB.  I say maybe
>>>> because I haven't run Sandman's script on my own Linux system yet.
>>>>
>>>>
>>>
>>> This one's fairly slow: times between 0.07 sec and 0.09 sec
>>> just for these few lines.
>>>
>> ...
>>
>> Terrible.  Approximately 30 sec for 6000 records.  All those
>> csplit tempfiles are expensive.  Have to try a different approach.
> 
> 
> Very slow - you're off your game.
> 
> 4.39 sec for 1000 loops with my VB code.
> 
> If I remove the 4 screen Echo statements, it's 0.17 seconds to parse 
> 6000 strings.
> 
> VB FTFW!  Finally!
> 
 
Yeah.  I'm getting 0.089 for 6000 on a nearly finished (non-echo'ing)
translation that doesn't create and destroy a crapload of tempfiles.
echo'ing is about 0.37



 
 

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


#351145

FromDFS <nospam@dfs.com>
Date2016-04-21 11:06 -0400
Message-ID<nfaq45$cjh$1@dont-email.me>
In reply to#351112
On 4/20/2016 11:56 PM, owl wrote:
> DFS <nospam@dfs.com> wrote:
>> On 4/20/2016 10:45 PM, owl wrote:
>>> owl <owl@rooftop.invalid> wrote:
>>>> DFS <nospam@dfs.com> wrote:
>>> ...
>>>>>
>>>>> It makes sense for perl to be shorter, but to be 1/3 the lines and run
>>>>> in (maybe) 1/10th the time is kind of embarrassing for VB.  I say maybe
>>>>> because I haven't run Sandman's script on my own Linux system yet.
>>>>>
>>>>>
>>>>
>>>> This one's fairly slow: times between 0.07 sec and 0.09 sec
>>>> just for these few lines.
>>>>
>>> ...
>>>
>>> Terrible.  Approximately 30 sec for 6000 records.  All those
>>> csplit tempfiles are expensive.  Have to try a different approach.
>>
>>
>> Very slow - you're off your game.
>>
>> 4.39 sec for 1000 loops with my VB code.
>>
>> If I remove the 4 screen Echo statements, it's 0.17 seconds to parse
>> 6000 strings.
>>
>> VB FTFW!  Finally!
>>
>
> Yeah.  I'm getting 0.089 for 6000 on a nearly finished (non-echo'ing)
> translation that doesn't create and destroy a crapload of tempfiles.
> echo'ing is about 0.37

zippy.  Unfortunately, you were eliminated in Round 1.




$ cscript /nologo parser.vbs 1000
0.156

I got mine down a little, but that's as fast as it's gonna get.


Each loop splits 6 strings:

For i = 1 to WScript.Arguments.Item(0)
  call parseString("name like *pizza")
  call parseString("name like *pizza ; zip=30303")
  call parseString("name like *pizza;zip=30303;street like *Buford Hwy")

  call parseString("state=GA")
  call parseString("state=GA;name=Burger King")
  call parseString("state=GA;name=Burger King;ziplike303*")
Next


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


#351154

Fromowl <owl@rooftop.invalid>
Date2016-04-21 16:13 +0000
Message-ID<ghjdow03.ata4@rooftop.invalid>
In reply to#351145
DFS <nospam@dfs.com> wrote:
> On 4/20/2016 11:56 PM, owl wrote:
>> DFS <nospam@dfs.com> wrote:
>>> On 4/20/2016 10:45 PM, owl wrote:
>>>> owl <owl@rooftop.invalid> wrote:
>>>>> DFS <nospam@dfs.com> wrote:
>>>> ...
>>>>>>
>>>>>> It makes sense for perl to be shorter, but to be 1/3 the lines and run
>>>>>> in (maybe) 1/10th the time is kind of embarrassing for VB.  I say maybe
>>>>>> because I haven't run Sandman's script on my own Linux system yet.
>>>>>>
>>>>>>
>>>>>
>>>>> This one's fairly slow: times between 0.07 sec and 0.09 sec
>>>>> just for these few lines.
>>>>>
>>>> ...
>>>>
>>>> Terrible.  Approximately 30 sec for 6000 records.  All those
>>>> csplit tempfiles are expensive.  Have to try a different approach.
>>>
>>>
>>> Very slow - you're off your game.
>>>
>>> 4.39 sec for 1000 loops with my VB code.
>>>
>>> If I remove the 4 screen Echo statements, it's 0.17 seconds to parse
>>> 6000 strings.
>>>
>>> VB FTFW!  Finally!
>>>
>>
>> Yeah.  I'm getting 0.089 for 6000 on a nearly finished (non-echo'ing)
>> translation that doesn't create and destroy a crapload of tempfiles.
>> echo'ing is about 0.37
> 
> zippy.  Unfortunately, you were eliminated in Round 1.
> 
> 
> 
> 
> $ cscript /nologo parser.vbs 1000
> 0.156
> 
> I got mine down a little, but that's as fast as it's gonna get.
> 
> 
> Each loop splits 6 strings:
> 
> For i = 1 to WScript.Arguments.Item(0)
>  call parseString("name like *pizza")
>  call parseString("name like *pizza ; zip=30303")
>  call parseString("name like *pizza;zip=30303;street like *Buford Hwy")
> 
>  call parseString("state=GA")
>  call parseString("state=GA;name=Burger King")
>  call parseString("state=GA;name=Burger King;ziplike303*")
> Next
> 
> 
You don't appear to be opening an input file.  Just timing repeated
function calls without the overhead of file I/O doesn't tell you much.
Also, what is your output format?  Do you print the "var field1 ="?
Not hard to code, but every byte counts when you're writing 6000 lines
to an output file or printing to stdout.

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


#351204

FromDFS <nospam@dfs.com>
Date2016-04-21 17:27 -0400
Message-ID<nfbgdb$4l6$1@dont-email.me>
In reply to#351154
On 4/21/2016 12:13 PM, owl wrote:
> DFS <nospam@dfs.com> wrote:
>> On 4/20/2016 11:56 PM, owl wrote:
>>> DFS <nospam@dfs.com> wrote:
>>>> On 4/20/2016 10:45 PM, owl wrote:
>>>>> owl <owl@rooftop.invalid> wrote:
>>>>>> DFS <nospam@dfs.com> wrote:
>>>>> ...
>>>>>>>
>>>>>>> It makes sense for perl to be shorter, but to be 1/3 the lines and run
>>>>>>> in (maybe) 1/10th the time is kind of embarrassing for VB.  I say maybe
>>>>>>> because I haven't run Sandman's script on my own Linux system yet.
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> This one's fairly slow: times between 0.07 sec and 0.09 sec
>>>>>> just for these few lines.
>>>>>>
>>>>> ...
>>>>>
>>>>> Terrible.  Approximately 30 sec for 6000 records.  All those
>>>>> csplit tempfiles are expensive.  Have to try a different approach.
>>>>
>>>>
>>>> Very slow - you're off your game.
>>>>
>>>> 4.39 sec for 1000 loops with my VB code.
>>>>
>>>> If I remove the 4 screen Echo statements, it's 0.17 seconds to parse
>>>> 6000 strings.
>>>>
>>>> VB FTFW!  Finally!
>>>>
>>>
>>> Yeah.  I'm getting 0.089 for 6000 on a nearly finished (non-echo'ing)
>>> translation that doesn't create and destroy a crapload of tempfiles.
>>> echo'ing is about 0.37
>>
>> zippy.  Unfortunately, you were eliminated in Round 1.
>>
>>
>>
>>
>> $ cscript /nologo parser.vbs 1000
>> 0.156
>>
>> I got mine down a little, but that's as fast as it's gonna get.
>>
>>
>> Each loop splits 6 strings:
>>
>> For i = 1 to WScript.Arguments.Item(0)
>>   call parseString("name like *pizza")
>>   call parseString("name like *pizza ; zip=30303")
>>   call parseString("name like *pizza;zip=30303;street like *Buford Hwy")
>>
>>   call parseString("state=GA")
>>   call parseString("state=GA;name=Burger King")
>>   call parseString("state=GA;name=Burger King;ziplike303*")
>> Next
>>
>>
> You don't appear to be opening an input file.  Just timing repeated
> function calls without the overhead of file I/O doesn't tell you much.

Well, it at least tells you how efficient the language and/or code is at 
parsing strings.


Note: The Committee For The Consideration Of Crap sed Code voted you 
off. 30 seconds to execute 6000 parses and file writes was considered 
unacceptable. The Committee will accept no appeals.



> Also, what is your output format?  Do you print the "var field1 ="?

  fOut.WriteLine "var field1 = '" & fld1 & "'"
  fOut.WriteLine "var value1 = '" & val1 & "'"
  fOut.WriteLine "var field2 = '" & fld2 & "'"
  fOut.WriteLine "var value2 = '" & val2 & "'"
  fOut.WriteLine "var fleld3 = '" & fld3 & "'"
  fOut.WriteLine "var value3 = '" & val3 & "'"



> Not hard to code, but every byte counts when you're writing 6000 lines
> to an output file or printing to stdout.

no echo, no files written
$ cscript /nologo parser.vbs 1000
0.156

no echo, one 6-line file written 6000x
$ cscript /nologo parser.vbs 1000
6.551






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


#351279

Fromowl <owl@rooftop.invalid>
Date2016-04-22 19:07 +0000
Message-ID<ghjdki893.afj@rooftop.invalid>
In reply to#351204
DFS <nospam@dfs.com> wrote:
...
> 
> no echo, no files written
> $ cscript /nologo parser.vbs 1000
> 0.156
> 
> no echo, one 6-line file written 6000x
> $ cscript /nologo parser.vbs 1000
> 6.551
> 

Yeah, I only got the shell script version down to 13 sec.
Pathetic.  I rewrote it in C, with same functionality:

2.7 sec to read in a 6000 line file, parse the data, reformat it,
and write to a 36,000-line file.  That's using with redirection
for writing the output file.  It might be faster if I coded creation
of the output file. 

BTW, are you reading a file for input, or preloading it in an array?

anon@lowtide:~/code/dfs/nah$ head -n 6 input_e
state=GA 
state=GA ; name = Burger King
state=GA ; name = Burger King ; zip like 303* 
city = Atlanta
state=TN ; name like Burger* ; street like Main*
state=GA ; name like *pizza ; zip = 30017
anon@lowtide:~/code/dfs/nah$

"input_e" is composed of 1000 copies of the above 6-line list, giving
a total of 6000 lines.

anon@lowtide:~/code/dfs/nah$ wc -l input_e
6000 input_e
anon@lowtide:~/code/dfs/nah$

Reading that file and parsing the 6000 lines, outputing a 36000-line
file: 

anon@lowtide:~/code/dfs/nah$ time ./blah input_e > output

real	0m2.713s
user	0m2.708s
sys	0m0.004s
anon@lowtide:~/code/dfs/nah$

anon@lowtide:~/code/dfs/nah$ wc -l output
36000 output
anon@lowtide:~/code/dfs/nah$

This is what the output file looks like:

anon@lowtide:~/code/dfs/nah$ head -n 36 output
field1 = 'state'
value1 = 'GA'
field2 = ''
value2 = ''
field3 = ''
value3 = ''
field1 = 'state'
value1 = 'GA'
field2 = 'name'
value2 = 'Burger King'
field3 = ''
value3 = ''
field1 = 'state'
value1 = 'GA'
field2 = 'name'
value2 = 'Burger King'
field3 = 'zip'
value3 = '303*'
field1 = 'city'
value1 = 'Atlanta'
field2 = ''
value2 = ''
field3 = ''
value3 = ''
field1 = 'state'
value1 = 'TN'
field2 = 'name'
value2 = 'Burger*'
field3 = 'street'
value3 = 'Main*'
field1 = 'state'
value1 = 'GA'
field2 = 'name'
value2 = '*pizza'
field3 = 'zip'
value3 = '30017'
anon@lowtide:~/code/dfs/nah$ 

anon@lowtide:~/code/dfs/nah$ tail -n 36 output
field1 = 'state'
value1 = 'GA'
field2 = ''
value2 = ''
field3 = ''
value3 = ''
field1 = 'state'
value1 = 'GA'
field2 = 'name'
value2 = 'Burger King'
field3 = ''
value3 = ''
field1 = 'state'
value1 = 'GA'
field2 = 'name'
value2 = 'Burger King'
field3 = 'zip'
value3 = '303*'
field1 = 'city'
value1 = 'Atlanta'
field2 = ''
value2 = ''
field3 = ''
value3 = ''
field1 = 'state'
value1 = 'TN'
field2 = 'name'
value2 = 'Burger*'
field3 = 'street'
value3 = 'Main*'
field1 = 'state'
value1 = 'GA'
field2 = 'name'
value2 = '*pizza'
field3 = 'zip'
value3 = '30017'
anon@lowtide:~/code/dfs/nah$ 

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


#351103

FromSteve Carroll <fretwizzen@gmail.com>
Date2016-04-20 19:01 -0700
Message-ID<c49e196b-31df-4411-b8f2-1209bfb94e19@googlegroups.com>
In reply to#350996
On Wednesday, April 20, 2016 at 3:37:44 PM UTC, 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.

Where is Snit to say how he would do this on OS X? Is this task too hard for his precious Automator / AppleScript crap? LOL!

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


#351219

FromFabian Russell <fb@zen.info>
Date2016-04-22 09:37 +0000
Message-ID<nfcrd20131u@news6.newsguy.com>
In reply to#350996
On Wed, 20 Apr 2016 11:37:41 -0400, DFS wrote:

> 
> If someone posts a 2-line perl solution, I'm hurling.
>

Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!

The dumb-fuck Microshit lackey demonstrates his incompetence
and idiocy yet again.

Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!

Two lines?  How about one line?

How about a SINGLE SOLITARY FUCKING LINE of Perl code?

Well, here is the complete Perl script and its one-line
essence:

#! /usr/bin/perl -w
use warnings;
use strict;

my @vals;
my $line="";
my $val="";

# Take your pick of any string below by commenting/uncommenting
# $line="state=GA";
# $line="state=GA ; name = Burger King";
$line="state=GA ; name = Burger King ; zip like 303*";

##################################################
# HERE IS THE ONE SINGLE SOLITARY FUCKING LINE!!!
##################################################

$line =~ s/( like )|( = )|( ; )|[=;]/!/ig; @vals = split /!/, $line;

foreach $val (@vals) {
print "$val\n";
}


Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!

Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!

Let's see you beat that with your Microshit junk.

The script does need some refinement but that kind of
task is for dumb-fuck lackeys and imbecilic code monkeys.

So go to it, lackey.  Get working, dog.

Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!

GNU/Linux.  The ONLY choice for REAL men.

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


#351247

FromNorman Peelman <npeelman@cfl.rr.com>
Date2016-04-22 08:33 -0400
Message-ID<nfd5gl$p94$1@dont-email.me>
In reply to#351219
On 04/22/2016 05:37 AM, Fabian Russell wrote:
> On Wed, 20 Apr 2016 11:37:41 -0400, DFS wrote:
>
>>
>> If someone posts a 2-line perl solution, I'm hurling.
>>
>
> Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!
>
> The dumb-fuck Microshit lackey demonstrates his incompetence
> and idiocy yet again.
>
> Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!
>
> Two lines?  How about one line?
>
> How about a SINGLE SOLITARY FUCKING LINE of Perl code?
>
> Well, here is the complete Perl script and its one-line
> essence:
>
> #! /usr/bin/perl -w
> use warnings;
> use strict;
>
> my @vals;
> my $line="";
> my $val="";
>
> # Take your pick of any string below by commenting/uncommenting
> # $line="state=GA";
> # $line="state=GA ; name = Burger King";
> $line="state=GA ; name = Burger King ; zip like 303*";
>
> ##################################################
> # HERE IS THE ONE SINGLE SOLITARY FUCKING LINE!!!
> ##################################################
>
> $line =~ s/( like )|( = )|( ; )|[=;]/!/ig; @vals = split /!/, $line;
>
> foreach $val (@vals) {
> print "$val\n";
> }
>

  While I am somewhat amused by your enthusiasm, I actually count 9 
uncommented lines. One of those lines actually consists of 2 commands, 
so it's really 10 lines... and... the workhorse of this script is really 
just a RegEx that would probably work (if it does work - untested) in VB 
(and others) as well.

  Second, again your enthusiasm towards linux is noted - perl also runs 
on Windows so i'm not really sure where your going with the whole Linux 
is for men angle.


-- 
BTW, I do use Linux.

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


#351310

FromFabian Russell <fb@zen.info>
Date2016-04-22 22:03 +0000
Message-ID<nfe73521m1r@news6.newsguy.com>
In reply to#351247
On Fri, 22 Apr 2016 08:33:38 -0400, Norman Peelman wrote:

> 
>   While I am somewhat amused by your enthusiasm ...
>

Shaddup you boring, stupid twit.  Who asked for your worthless
opinions?

>
> I actually count 9 uncommented lines.
>

Well, well, well.  The smart fuck can count.  So can any school girl.

Go count the hairs around your asshole.


>
> One of those lines actually consists of 2 commands, 
>

Those two commands can be very easily combined into one.

I'll allow a smart fuck like you figure out how to do it.


>
> i'm not really sure where your going with the whole Linux 
> is for men angle.
>

Well, I'm certainly NOT going to Denmark, because there is
something rotten in the state thereof.

Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!

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


#351326

FromRichard King <kingsley651@webby.org>
Date2016-04-22 18:22 -0400
Message-ID<nfe81k$vr3$1@dont-email.me>
In reply to#351310
On 22 Apr 2016 22:03:17 GMT, Fabian Russell wrote:

> On Fri, 22 Apr 2016 08:33:38 -0400, Norman Peelman wrote:
> 
>> 
>>   While I am somewhat amused by your enthusiasm ...
>>
> 
> Shaddup you boring, stupid twit.  Who asked for your worthless
> opinions?

Your village has called, Fabian.
It seems their idiot has escaped, once again, and they want you back.

-- 
RK

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


#351284

Fromowl <owl@rooftop.invalid>
Date2016-04-22 19:48 +0000
Message-ID<ghjdke802.ag4u@rooftop.invalid>
In reply to#351219
Fabian Russell <fb@zen.info> wrote:
> On Wed, 20 Apr 2016 11:37:41 -0400, DFS wrote:
> 
>> 
>> If someone posts a 2-line perl solution, I'm hurling.
>>
> 
> Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!
> 
> The dumb-fuck Microshit lackey demonstrates his incompetence
> and idiocy yet again.
> 
> Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!
> 
> Two lines?  How about one line?
> 
> How about a SINGLE SOLITARY FUCKING LINE of Perl code?
> 
> Well, here is the complete Perl script and its one-line
> essence:
> 
> #! /usr/bin/perl -w
> use warnings;
> use strict;
> 
> my @vals;
> my $line="";
> my $val="";
> 
> # Take your pick of any string below by commenting/uncommenting
> # $line="state=GA";
> # $line="state=GA ; name = Burger King";
> $line="state=GA ; name = Burger King ; zip like 303*";
> 
> ##################################################
> # HERE IS THE ONE SINGLE SOLITARY FUCKING LINE!!!
> ##################################################
> 
> $line =~ s/( like )|( = )|( ; )|[=;]/!/ig; @vals = split /!/, $line;
> 
> foreach $val (@vals) {
> print "$val\n";
> }
> 
> 
> Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!
> 
> Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!
> 
> Let's see you beat that with your Microshit junk.
> 
> The script does need some refinement but that kind of
> task is for dumb-fuck lackeys and imbecilic code monkeys.
> 
> So go to it, lackey.  Get working, dog.
> 
> Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!
> 
> GNU/Linux.  The ONLY choice for REAL men.
> 

anon@lowtide:~/code/dfs/nah$ ./fab1
state
GA
anon@lowtide:~/code/dfs/nah$ ./fab2
state
GA
name
Burger King
anon@lowtide:~/code/dfs/nah$ ./fab3
state
GA
name
Burger King
zip
303*
anon@lowtide:~/code/dfs/nah$ 

FAIL!
That's not the correct output format.  It's supposed to output field1-field3
and value1-value3, regardless of whether those fields exist for a given
line, like below, with labels and placeholders for empty fields:

anon@lowtide:~/code/dfs/nah$ cat input
state=GA
state=GA ; name = Burger King
state=GA ; name = Burger King ; zip like 303*
city = Atlanta
state=TN ; name like Burger* ; street like Main*
state=GA ; name like *pizza ; zip = 30017
anon@lowtide:~/code/dfs/nah$ 
anon@lowtide:~/code/dfs/nah$ ./blah input >output
anon@lowtide:~/code/dfs/nah$ 
anon@lowtide:~/code/dfs/nah$ cat output
var field1 = 'state'
var value1 = 'GA'
var field2 = ''
var value2 = ''
var field3 = ''
var value3 = ''
var field1 = 'state'
var value1 = 'GA'
var field2 = 'name'
var value2 = 'Burger King'
var field3 = ''
var value3 = ''
var field1 = 'state'
var value1 = 'GA'
var field2 = 'name'
var value2 = 'Burger King'
var field3 = 'zip'
var value3 = '303*'
var field1 = 'city'
var value1 = 'Atlanta'
var field2 = ''
var value2 = ''
var field3 = ''
var value3 = ''
var field1 = 'state'
var value1 = 'TN'
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]


#351298

FromDFS <nospam@dfs.com>
Date2016-04-22 17:24 -0400
Message-ID<nfe4ji$h0k$1@dont-email.me>
In reply to#351284
On 4/22/2016 3:48 PM, owl wrote:
> Fabian Russell <fb@zen.info> wrote:

> state
> GA
> name
> Burger King
> zip
> 303*
> anon@lowtide:~/code/dfs/nah$
>
> FAIL!
> That's not the correct output format.  It's supposed to output field1-field3
> and value1-value3, regardless of whether those fields exist for a given
> line, like below, with labels and placeholders for empty fields:

Actually, I didn't specify an output format, or any output at all.  I 
showed an output - marked 'for testing' - just to prove the code worked. 
  All I wanted was a program that parsed 3 different line formats 
correctly, and declared and populated the variables.

I can't tell if your initial sed code populated any variables, but your 
output made it look like it did.  Does your new C version declare and 
populate 6 variables?

Fabian's perl looks to be another of his code FAILS.  I don't see where 
he specifies 6 different variables.

As I said in the 1st sentence of the 1st post:

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

The fruitcase was so excited to show a short perl version that he 
ignored the rules.

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


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

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


csiph-web