Advertisement
djuggler

dynamically reference a structure of arrays of structure

Jul 20th, 2015
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cfscript>
  2.     testdoug = structNew();
  3.     testdoug.dataarray = arrayNew(1);
  4.  
  5.     testdoug.dataarray[1] = structNew();
  6.     testdoug.dataarray[1].finaldata = 'mary';
  7.     testdoug.dataarray[1].guid = '100019';
  8.     testdoug.dataarray[1].morearray = arrayNew(1);
  9.     testdoug.dataarray[1].morearray[1] = structNew();
  10.     testdoug.dataarray[1].morearray[1].finaldata = 'george';
  11.     testdoug.dataarray[1].morearray[1].guid = '100021';
  12.  
  13.     testdoug.dataarray[2] = structNew();
  14.     testdoug.dataarray[2].finaldata = 'ralpha';
  15.     testdoug.dataarray[2].guid = '100035';
  16.     testdoug.dataarray[2].morearray = arrayNew(1);
  17.     testdoug.dataarray[2].morearray[1] = structNew();
  18.     testdoug.dataarray[2].morearray[1].finaldata = 'lucy';
  19.     testdoug.dataarray[2].morearray[1].guid = '100043';
  20.  
  21.     testdoug.dataarray[2].morearray[1].morearray = arrayNew(1);
  22.     testdoug.dataarray[2].morearray[1].morearray[1] = structNew();
  23.     testdoug.dataarray[2].morearray[1].morearray[1].finaldata = 'ethel';
  24.     testdoug.dataarray[2].morearray[1].morearray[1].guid = '100092';
  25.     testdoug.dataarray[2].morearray[1].morearray[2] = structNew();
  26.     testdoug.dataarray[2].morearray[1].morearray[2].finaldata = 'lisa';
  27.     testdoug.dataarray[2].morearray[1].morearray[2].guid = '100089';
  28.  
  29.     writeDump(testdoug);
  30.     writeOutput("<hr>");
  31. </cfscript>
  32.  
  33. This pattern could continue many levels deep.
  34.  
  35. Goal: Use structFindValue to locate a particular GUID. Then change the value of final data associated with that particular GUID.
  36. Attemps to dynamically build the path in a variable then evaluate that variable to be able to modify its value have failed.
  37.  
  38. Challenge: Given the structure above. Search for GUID 100092 and change the value of finaldata from ethel to ricky.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement