[ic] Possible minor bug (?): '-' and $Scratch->{var-name}

Mike Heins interchange-users@interchange.redhat.com
Fri Aug 24 16:48:00 2001


Quoting Ed LaFrance (edl@newmediaems.com):
> Hi all -
> 
> Working on some code in an IC 4.6.5 catalog, I found that I could set and 
> view the contents of a scratch variable which contains a dash in its name 
> using IC tags:
> 
> [set var-name]something[/set]
> [scratch var-name]
> 
> but operations failed within a Perl block:
> 
> [set var-name][/set]
> [perl]
>          $Scratch->{var-name} = "foo";
>          return;
> [/perl]
> [scratch var-name]
> 
> In the latter example, var-name remains empty; no message in the error 
> log.  Removing the dash from var-name fixes the problem instantly.  It also 
> fixes the problem to enclose the var-name in single quotes:
> 
> [perl]
>          $Scratch->{'var-name'} = "foo";
>          return;
> [/perl]
> 
> ...and furthermore, using an underscore instead of a dash works. This is 
> pretty minor, but has me wondering; is this a side-effect of code intended 
> for other purposes or an undocumented character usage restriction?

It is a Perl thing, no more, no less. '-' is a minus sign, and not
a word character. You can only use word characters in variable names
unless you quote them. (Knowledgeable Perl people will know the one
exception -- when you prepend the word with a - sign and have no leading word
chars.)

Remember, this has nothing to do with any other reference -- for instance,
you can do:

	$label = 'var-name';
	return $Scratch->{$label};

That is why I rarely if ever use - in a name. Any places you see it,
the code came from somewhere else.

-- 
Red Hat, Inc., 3005 Nichols Rd., Hamilton, OH  45013
phone +1.513.523.7621      <mheins@redhat.com>

Few blame themselves until they have exhausted all other possibilities.
 -- anonymous