# Golf Q: \$h ?

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on

In an old FWP post I found online, there is a golfing construct I
can't figure out; this is all the post says

\$h is one less than ++\$h

If it weren't for the leading backslash, the interpretation of "one
less" would be obvious and hardly worth remarking upon in such a
post.  But given the leading backslash, I figure that the "one
less" is referring to "one fewer characters".  Still, I can't figure
out what the whole thing means.  Any help would be much appreciated.

TIA!

jill

--
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.

## Re: Golf Q: \$h ?

> In an old FWP post I found online, there is a golfing construct I
> can't figure out; this is all the post says
>
>   \$h is one less than ++\$h
>
> If it weren't for the leading backslash, the interpretation of "one
> less" would be obvious and hardly worth remarking upon in such a
> post.  But given the leading backslash, I figure that the "one
> less" is referring to "one fewer characters".  Still, I can't figure
> out what the whole thing means.  Any help would be much appreciated.

That "one less" refers to the number of characters is my interpretation
too. I assume the idea is to make a hash table entry exist by referring
to it (I think that's what's called "autovivification"):

\$h1;
++\$h2;

\$h0 = exists \$h0 ? "yes" : "no";
\$h1 = exists \$h1 ? "yes" : "no";
\$h2 = exists \$h2 ? "yes" : "no";

print "\$h0 \$h1 \$h2";

prints "no yes yes".

## Re: Golf Q: \$h ?

>> In an old FWP post I found online, there is a golfing construct I
>> can't figure out; this is all the post says
>>
>>   \$h is one less than ++\$h
>>
>> If it weren't for the leading backslash, the interpretation of "one
>> less" would be obvious and hardly worth remarking upon in such a
>> post.  But given the leading backslash, I figure that the "one
>> less" is referring to "one fewer characters".  Still, I can't figure
>> out what the whole thing means.  Any help would be much appreciated.

>That "one less" refers to the number of characters is my interpretation
>too. I assume the idea is to make a hash table entry exist by referring
>to it (I think that's what's called "autovivification"):

>    \$h1;
>    ++\$h2;

>    \$h0 = exists \$h0 ? "yes" : "no";
>    \$h1 = exists \$h1 ? "yes" : "no";
>    \$h2 = exists \$h2 ? "yes" : "no";

>    print "\$h0 \$h1 \$h2";

>prints "no yes yes".

Thanks!

jill

--
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.