Page 1 of 1 1
Topic Options
#82013 - 2003-02-19 05:23 PM Using $ inside quotes
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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>


Edited by kdyer (2005-05-25 11:13 PM)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#82014 - 2003-02-20 04:51 AM Re: Using $ inside quotes
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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 ]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


Moderator:  Jochen, Radimus, Glenn Barnas, Allen, Arend_, ShaneEP, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.048 seconds in which 0.021 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org