auto increasing permanent variables

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
tiago
Posts: 589
Joined: 14 Feb 2011 21:41

auto increasing permanent variables

Post by tiago »

Is there a way to auto-increase values for permanent variables?
Following script will give an idea:

Code: Select all

   $ep = ",";
   $info = <clipboard>;
   $test = gettoken("$info", "count", "<crlf>");
   perm $p_nm1, $p_nm2, $p_nm3, $p_nm4, $p_nm5, $p_nm6, $p_nm7, $p_nm8, $p_nm9;
   $p_nm = "";
        foreach($line, $info, "<crlf>")
      {
   $index = 1;
   WHILE ($index != "9") {
   $name = gettoken("$line", "$index", " ");
   IF ($name == "") { break; }
   ELSEIF ($name != "") {   }

//HERE IS THE PROBLEM!
   $p_nm $index = "$p_nm" . "$index" . "$name" . "$ep"; //HERE IS THE PROBLEM!
   $index++;

//from now on, unfinished, ie, properly stopping at permanent var nr. 9 and store items, etc - not a problem
                         }
      }
   text "$p_nm1<crlf><crlf>$p_nm2<crlf><crlf>$p_nm3<crlf><crlf>$p_nm4<crlf><crlf>$p_nm5<crlf><crlf>$p_nm6<crlf><crlf>$p_nm7<crlf><crlf>$p_nm8<crlf><crlf>$p_nm9<crlf>"
   releaseglobals;
   status "done!";
If that's not possible, how to achieve similar effect, ie, getting several elements on a phrase and store then separately, according to their positions?
Basically each permaVar must store items respectively to their positions on a given phrase, so
Products ($p_nm1) of ($p_nm2) Stanford ($p_nm3) Mill ($p_nm4)
Lakeshore ($p_nm1) Heavy ($p_nm2) Duty ($p_nm3) Products ($p_nm4)
then
$p_nm1 = Products, Lakeshore
$p_nm2 = of, Heavy
$p_nm3 = Stanford, Duty
$p_nm4 = Mill, Products
Any help will be appreciated.
Power-hungry user!!!

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: auto increasing permanent variables

Post by tiago »

I did it the hard way* and it worked of course.
But then I realized that sc globals() kinda is forgotten if used along with sc foreach(). Same problem does not happen if I use regular WHILE loops instead. I am not sure whether it's a bug or not so I'd appreciate if anyone could enlighten me on this being or not the expected behavior. Tested on version 9.90.1018.

*$p_nm1, $p_nm2, $p_nm3 instead of neat "$p_nm" . "$index" = or equivalents.
Power-hungry user!!!

Post Reply