Golf Q: \$h{X} ?

J

J Krugman

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{X} is one less than ++$h{X}

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
 
A

Arndt Jonasson

J Krugman said:
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{X} is one less than ++$h{X}

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{X};
++$h2{X};

$h0 = exists $h0{X} ? "yes" : "no";
$h1 = exists $h1{X} ? "yes" : "no";
$h2 = exists $h2{X} ? "yes" : "no";

print "$h0 $h1 $h2";

prints "no yes yes".
 
J

J Krugman

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"):

$h0 = exists $h0{X} ? "yes" : "no";
$h1 = exists $h1{X} ? "yes" : "no";
$h2 = exists $h2{X} ? "yes" : "no";
print "$h0 $h1 $h2";
prints "no yes yes".

Thanks!

jill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top