|
2005-07-04
| ||
| 02:44 | • Deleted ticket [1230253fff]: match array plus 5 other changes artifact: 8335798952 user: dkf | |
|
2005-07-03
| ||
| 02:02 | • Closed ticket [1230253fff]. artifact: 7132cb9c8b user: msofer | |
| 01:30 | • Open ticket [1230253fff]. artifact: da082cfd8c user: elfring | |
|
2005-07-02
| ||
| 20:36 | • Pending ticket [1230253fff]. artifact: a1fc5f5f9d user: msofer | |
| 14:45 | • Open ticket [1230253fff]. artifact: ac86c60f87 user: elfring | |
| 05:57 | • Ticket [1230253fff]: 4 changes artifact: 2420807099 user: msofer | |
| 04:57 | • Closed ticket [1230253fff]. artifact: b3e463082f user: dkf | |
|
2005-07-01
| ||
| 23:14 | • Ticket [1230253fff]: 4 changes artifact: 1ce29f5e13 user: msofer | |
| 23:03 | • Ticket [1230253fff]: 5 changes artifact: f33c71af36 user: elfring | |
|
2005-06-30
| ||
| 18:01 | • Ticket [1230253fff]: 4 changes artifact: 8b7a779d9d user: msofer | |
| 10:07 | • New ticket [1230253fff]. artifact: f6ea632e8a user: elfring | |
match array
Deleted1230253fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-06-30 10:07:11
http://tcl.tk/man/tcl8.5/TclCmd/regexp.htm: I want that matches can be stored into an array instead of "subMatchVars". I imagine cases where I can not use finite and predefined variable names because the search pattern was dynamically constructed.
msoferplain2005-06-30 18:01:20
Logged In: YES user_id=148712 Doesn't the '-inline' option provide what you need? It returns the matches in a list.
elfringplain2005-07-01 23:03:52
Logged In: YES user_id=572001 Well, it can be one way for a solution. Can the extra conversion step of this list into an array be avoided? (Each data type has got its own advantages.)
msoferplain2005-07-01 23:14:29
Logged In: YES user_id=148712 I do not fully understand the spec for your request: what would be the array keys for the different matches? If it is the order in which they are found, the list result is the correct format - just access themby [lindex], or [foreach]. Or convert to an array if you think you must. In that case, my opinion is that the core should be doing it for you. If the array keys are something else (maybe some part of the regular expression itself?), maybe ... Although it is not at all clear to me yet how we could do this. Can you please provide an example of what would happen if this feature is implemented?
dkfplain2005-07-02 04:57:17
Logged In: YES user_id=79902 I see no need for such a thing. Quite apart from the -inline option described by Miguel, the -about option returns (among other things) the maximum number of subMatchVars required by a particular RE, so allowing for the construction of a command to perform the matching and place the submatches directly into any variable(s) chosen. This means that this would all be syntactic sugar at best (and is, of course, easily simulated using a procedure). (Maintainer Note: The [regexp] command, as opposed to the RE guts, is in Category 18)
msoferplain2005-07-02 05:57:53
Logged In: YES user_id=148712 Correcting a bad typo in my last comment here: "... my opinion is that the core should NOT be doing it for you."
elfringplain2005-07-02 14:45:48
Logged In: YES
user_id=572001
How do you think about this use case?
I imagine the following function calls to import mapping
tables into corresponding data structures.
set source1 {Pi/3.1415,Tax/0.16,}
set pattern1 {([^/]+)/(.+),}
regexp -all -array vector1 $pattern1 $source1
regexp -all -list contents1 $pattern1 $source1
set source2 {1-title:23-name:456-address:}
set pattern2 {([^\-]+)-(.*):}
regexp -all -type array -param vector2 $pattern2 $source2
regexp -all -type list -param contents2 $pattern2 $source2
msoferplain2005-07-02 20:36:49
Logged In: YES
user_id=148712
I still do not quite get it. I think you are proposing to
have a builtin capability to do something like
foreach {- key val} [regexp -all -inline $pattern $source] {
set vector($key) $val
}
What should happen if the pattern does not always produce an
even number of submatches? Would that be an error? What if
the pattern is capable of producing an odd number of
submatches, but doesn't with the particular input : error or
not?
As it is, I do not think the complication is really worth
it. You can easily get this functionality in a proc. It is
quite unlikely that the performance impact will be
noticeable, if this is what is worrying you: proc calls and
[set] are quite a bit faster than [regexp] in any case.
elfringplain2005-07-03 01:30:19
Logged In: YES user_id=572001 What is your intention with the use of the variable name "-"? Well, I guess that this kind of loop for the conversion from a list to an array can be more efficiently implemented in C code. I assume that there are speed improvements and reduced memory consumption possible because the value copies to the variables (key, val) can be avoided in the internal processing.
msoferplain2005-07-03 02:02:44
Logged In: YES user_id=148712 The variable name "-" is just a mnemonic for "a variable that I actually do not care about, and will not be dereferencing". As to the performance win: trust me, it is not there in any simple implementation. It will actually be slower. It could be made marginally faster, at a complexity cost that is way beyond reasonable. Returning the ticket to dkf, as (a) this is not my area and (b) he did claim it. Please do not alter maintainer assignments arbitrarily.
dkfplain2005-07-04 02:44:20
Logged In: YES user_id=79902 To reaffirm: requested feature can be implemented using a Tcl procedure, and adding it to the core is a fair bit of effort which would be better spent elsewhere. All significant costs can be worked around in one way or another with existing facilities.
Log in (anonymous is fine) to add a comment.