Les
(KiX Master)
2003-02-19 05:23 PM
Using $ inside quotes

A word of caution on using $. The $ can in of itself be a variable, but it is not considered good practice to use it.

Take the following example:

break on
$="test"
$ ?
"\\Server\Users\@UserID$" ?
"\\Server\Users\@UserID$$" ?
get $_

If you assign a string or value to $, and then use sloppy coding for say, hidden shares, it will give you grief if using a KiX prior to 4.10 version. Assigned as a string,

Use "H:" "\\Server\Users\@UserID$"

would concatenate the @UserID and the $ as if it were:

"\\Server\Users\" + @UserID + $

The manual states that if a $ is used within quotes that it should be $$, as in:

Use "H:" "\\Server\Users\@UserID$$"

Don't take the above examples of proper coding since they are not. They are simply to demonstrate the issue of $ in quotes.

Check out Ruud's comment on the use of $ in a thread over at ScriptLogic.

intended behavior? "$=" creates a variable

<small>[ 20. February 2003, 05:02: Message edited by: LLigetfa ]</small>


Les
(KiX Master)
2003-02-20 04:51 AM
Re: Using $ inside quotes

OK, so I took some heat for saying that using $ as a var is not considered good practice. Sure, you can use it with impunity and better your golf score, but beware that if someone adopts your code and adds it to theirs, things can go amuck. Let's not forget that the topic is about $ in quotes more than it is about using $ as a var.

I'd like to commend Ruud for saying that "Vars inside strings are evil" because they are! I only wish he would have taken it a step further and made the default SetOption('NoVarsInStrings','on') but since he didn't, everyone should set it in their script. Ruud did change KiX from 4.10 on to no longer resolve '$' as a var when used inside strings but code often has a way of ending up in previous versions.

Now to add to the confusion. So, we read that vars in strings are evil, and that we should code like this:
code:
Use 'H:' '\\Server\Users\'+@UserID+'$$'  

But if we set SetOption('NoVarsInStrings','on') this would result in a doubling of the $$:
quote:
\\Server\Users\UserID$$
The manual does tell us that if we set SetOption('NoVarsInStrings','on'), that "if this option is enabled, any '$' character in a string will be left as-is".

[ 20. February 2003, 05:18: Message edited by: LLigetfa ]