AutoHotkey Community

It is currently May 27th, 2012, 3:57 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: May 13th, 2011, 12:34 am 
Offline

Joined: July 15th, 2006, 6:07 pm
Posts: 254
I've got an application that creates an array such as:
Code:
array%i%%j% = different stuff
Where 'i' and 'j' are not necessarily numbers but strings. (valid variable names however) I guess I could keep track with a list of variables that I've set and then unset them by parsing the list but I was wondering if there was something effectively like
Code:
;regex syntax
array.* =
that would unset all that match the expression in the variable name.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2011, 1:47 am 
Offline

Joined: May 13th, 2010, 10:11 am
Posts: 352
Location: Houston, Tx.
I haven't discovered all of AHK_L's Array options, but I suggest reading into it.

For pseudo-arrays, you'll have to reset them manually:
Code:
;Initialize variables
list_1 := "1234"
list_2 := "5678"
list_3 := "9012"

;Reset
Loop, 3
    list_%A_Index% :=


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2011, 3:41 am 
Offline

Joined: July 15th, 2006, 6:07 pm
Posts: 254
Thanks but as mentioned I'm not using typical array indexing but more like a "key" -> "value" approach where the "keys" are not known before hand so a simplistic loop is not a workable solution. I was looking for something like this where I don't need to keep track of the indexes.

Code:
loop
{
  i := getnexti()
  j := getnextj()
  array%i%%j% := get(SomeStuff)
  .
  . (break sometime)
}
return

reset:
 dosomethinginteresting("array.*")
return


Now of course I could do something like:

Code:
arraylist =
loop
{
  i := getnexti()
  j := getnextj()
  arraylist =%arraylist%%i%%j%© 
  array%i%%j% := get(SomeStuff)
  .
  . (break sometime)
}
return

reset:
loop, parse, arraylist,©
 array%A_LoopField% :=
return


which isn't a big deal to do but thought it was intriguing to unset variables with a regex approach not needing to keep track of keys manually. (And I'm totally amazed at what some of the gurus around here can do. So thought I'd ask.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2011, 3:54 am 
Online

Joined: April 8th, 2009, 7:49 pm
Posts: 6073
Location: San Diego, California
Hi wakewatcher,

Might I ask >why< you want to do this ?

What information have you read?

What opinion has been posted?
What idea have you been persuing?

It would be preferable to have links to the source.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2011, 4:23 am 
Offline

Joined: July 15th, 2006, 6:07 pm
Posts: 254
Not sure I'm following you. But...

If its possible then I don't have to keep a list of set array variables used. (I have to unset them for the next iteration as the new data set may not use the key so don't want it to have an old value in it.)

Not following you on information read? Opinion Posted?

The idea I'm pursuing is the function dosomethinginteresting("array.*",value = "") where the function would unset or assign (per the optional parameter) all currently set used (set) variables that start with "array", e.g. (arrayfigtree, arraycherrytree). I figured that internally since this is an interpreted language that the "active" variables are know by the system. When a variable is set to null it no longer exists. Like I mentioned there's an easy way to do by tracking the array keys so this was more an academic question. Looks like I'm going down a rabbit hole on this so please no one spend any time on this unless you already know if its possible. Otherwise I'll assume its not possible.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2011, 4:52 am 
Online

Joined: April 8th, 2009, 7:49 pm
Posts: 6073
Location: San Diego, California
I asked why you would bother to clear variables.
Your current statements are a not real clear to me, but I understand the "academic question" basis.

I can suggest one thing. If the script is run again, all variables are "dumped".
If that is amiable to your methods, I suggest reviewing these commands:
http://www.autohotkey.com/docs/commands/Reload.htm
http://www.autohotkey.com/docs/commands ... stance.htm

If you are interested in a current list of variables, this is the only way I know to get it. http://www.autohotkey.com/docs/commands/ListVars.htm

for example:
Code:
a=1
b=2
c=3
listvars
msgbox


With a little work, you could extract the list from the "ListVars" window, parse the list and then erase the variables.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2011, 9:36 am 
Offline

Joined: July 15th, 2006, 6:07 pm
Posts: 254
You clear or set variables so they are always accurate. (And being null is a valid condition telling the (my) program there is nothing to act on for that key at that time. If you don't clear it then if it is accessed it contains the last value which at that particular time would be wrong.)

Reload and SingleInstance are not relevant as the intent is not to rerun the entire script or enforce a single instance of the script.

Screen scraping and parsing the varlist while perhaps an academic solution really isn't a practical solution. However if I can redirect the output of listvars into a variable then run the regex against it that might work. However obviously at a much greater cost than the solution I already presented.

Time to move on.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 13th, 2011, 10:34 am 
Offline

Joined: June 6th, 2006, 3:19 pm
Posts: 1654
Location: Denmark
To Arrays, perhaps.

_________________
RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2011, 1:32 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
If you know which keys were used, you should be able to clear each variable based on that. If you don't know which keys were used, how are you even using the so-called array? As for your original question:
Quote:
Is it possible to easily 'unset' an array somehow?
An actual array, yes, but you are using a pseudo-array, which is just a bunch of independent variables. There is no easy way to "unset" it other than by terminating the script (or returning from the function which contains it, if it is composed of local variables).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2011, 4:39 pm 
Offline

Joined: July 15th, 2006, 6:07 pm
Posts: 254
Thanks all.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Leef_me and 41 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group