Page 2 of 2

Re: Deref Anywhere is Major Break in Backward Compatibility

Posted: 14 Jul 2014 14:50
by TheQwerty
admin wrote:Wow, little overkill maybe? ;)
Probably... :lol:

And the Interpolate SC is definitely.

Re: Deref Anywhere is Major Break in Backward Compatibility

Posted: 14 Jul 2014 15:04
by nerdweed
If you wanted to go even further - I know we've seen some requests for fine tuning which variables are resolved so this deref SC could really be an interpolate SC with flag:
I have just been wondering how to avoid the variable on left side in a Heredoc from resolving. I had been using a place holder variable but it gets unmanagable with longer scripts

The below code fails and hence as it can't assign 2 to 1

Code: Select all

 $flag=1 ;
 $Check=<<<FOO
$flag=2 ;
#Foo ;
My current Workaround

Code: Select all

 $flag=1 ;
 $var_flag = '$flag' ;
 $Check=<<<FOO
$var_flag=2 ;
#Foo ;

Re: Deref Anywhere is Major Break in Backward Compatibility

Posted: 14 Jul 2014 15:29
by PeterH
Maybe some typo?

Test:

Code: Select all

 $flag=1 ;
 $Check=<<<FOO
$flag=2 ;
FOO;
Edit: I first saw the typo - but this doesn't help on not resolving variables in heredoc.

Re: Deref Anywhere is Major Break in Backward Compatibility

Posted: 14 Jul 2014 15:34
by TheQwerty
@nerdweed: I don't think the interpolate SC would actually help with that scenario. Currently you just have to be very smart about your usage of variables in and outside of the HEREDOC.

If I was hard-pressed to use the same variable in each I'd probably do some post-processing like so:

Code: Select all

 $flag = 1;
 $Check = <<<FOO
$:flag = $flag + 2;
FOO;
 $Check = Replace($Check, '$:', '$');
 Text $Check;
The problem is you have to pick a pattern that you know won't be in the interpolated HEREDOC - so I had to make sure I didn't put a literal '$:' in FOO and also that no variable could contain that.

No matter what using the same variable names sure makes it difficult to find a compromise between the desired functionality and legible code.

Maybe Don could give us a new XY var: '<$ flag>' which would get resolved to '$flag' thus making the above:

Code: Select all

 $flag = 1;
 $Check = <<<FOO
<$ flag> = $flag + 2;
FOO;
 Text $Check;
I suppose that could also offer another way to do derefs: '<*$ flag>'

Re: Deref Anywhere is Major Break in Backward Compatibility

Posted: 14 Jul 2014 15:36
by PeterH
@ dereference:

Seems the problem is because * is added in front of the variable, and so is ambiguous.

:idea: What about using eg. $*var, or even $$var? This is unique.

Re: Deref Anywhere is Major Break in Backward Compatibility

Posted: 14 Jul 2014 16:04
by nerdweed
PeterH wrote:Maybe some typo?
Yes, but only here. I typed it from memory and is was a dummy code. :biggrin:
TheQwerty wrote:No matter what using the same variable names sure makes it difficult to find a compromise between the desired functionality and legible code.
It was just a simple example. I have some scripts which I have added as UDC and use Heredoc to generate a runtime menu and load it - like here http://www.xyplorer.com/xyfc/viewtopic. ... 30#p104976
TheQwerty wrote: Maybe Don could give us a new XY var: '<$ flag>' which would get resolved to '$flag' thus making the above:

Code: Select all

 $flag = 1;
 $Check = <<<FOO
<$ flag> = $flag + 2;
FOO;
 Text $Check;
I suppose that could also offer another way to do derefs: '<*$ flag>'
This sounds great.

I will check the post processing idea as well. Thanks