Dynamically Created Variables and Values Attribution

Discuss and share scripts and script files...
Post Reply
SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Dynamically Created Variables and Values Attribution

Post by SkyFrontier »

Long time ago I needed to attribute values to dynamically created variables. Now and then I try to achieve the same since then but no success.

Is there a way, as of today's technowledge may allow this?

Code: Select all

   $re = "";
   $a = "ab;bc;cd";
   foreach ($tk, "$a", ";") {
   $op++;
// step;
   $re = "$re" . '$' . "$tk = $op<crlf>";

                            }
   $var = <<<hdc
$re
hdc;

//   load ("$var", , s);
////////////////////debug
//   text "$var";
////////////////////end of debug
// step;
// echo 1;

   foreach ($tk, "$var", "<crlf>") {
//   $op++;
// step;
//   $re = "$re" . '$' . "$tk = $op<crlf>";
// step;
   $varF = gettoken("$tk", 1, " = ");
   $val = gettoken("$tk", 2, " = ");
//   set eval($varF), "$val";
//   set "$varF", "$val";
// step;
//   set eval("$varF"), "$val";
//   $varF = replace ("$varF", "$", ""); set "$" . "$varF", "$val"; // lazy code - getting rid of '$'
//   $varF = replace ("$varF", "$", ""); set "$" . eval("$varF"), "$val"; // lazy code
//   $varF = replace ("$varF", "$", ""); set "$" . eval($varF), "$val"; // lazy code
   $varF = replace ("$varF", "$", ""); step; set "$" . "eval($varF)", "$val"; // lazy code
   set $varF, "$val"; // $varF sould be $ab; $bc; $cd

                                   }
Another usage for this is to have groups of values distributed among such dynamic number of variables. Currently I resource to a random number of variables in hopes they won't be exceeded by the number of value groups script finds - which is error prone.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Dynamically Created Variables and Values Attribution

Post by Marco »

I'm afraid it is not possible at the moment, eval() cannot set variables. I know because I tried. I wanted to build a list of dates (when DST begins and ends in a given year), like $dst_begin_2000 and $dst_end_2000, from 1998 to 2014. I couldn't, had to create such list by hand.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Dynamically Created Variables and Values Attribution

Post by SkyFrontier »

For reference: a trick to produce the desired result is creating the series of variables and shove it, along the whole script, into a chain of variables that later will be concatenated into a single one and executed under a load(),,s command.
Example: http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=14376
(the link leads to a method I created to auto-distribute a list of XY scripts into user-defined groups - or predefined maximum amount into each group - so a submenus categorization can be achieved)
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Post Reply