Golf Q: \$h{X} ?

Discussion in 'Perl Misc' started by J Krugman, Apr 4, 2005.

  1. J Krugman

    J Krugman Guest

    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


    --
    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.
     
    J Krugman, Apr 4, 2005
    #1
    1. Advertising

  2. J Krugman <> writes:
    > 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".
     
    Arndt Jonasson, Apr 4, 2005
    #2
    1. Advertising

  3. J Krugman

    J Krugman Guest

    In <> Arndt Jonasson <> writes:


    >J Krugman <> writes:
    >> 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".


    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.
     
    J Krugman, Apr 4, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Hoy

    my golf game needs gui

    Mike Hoy, Jun 9, 2005, in forum: Python
    Replies:
    2
    Views:
    273
    Mike Meyer
    Jun 9, 2005
  2. Carl Drinkwater
    Replies:
    7
    Views:
    506
    Paddy
    Sep 18, 2006
  3. Calvin Spealman
    Replies:
    3
    Views:
    334
    Neil Cerutti
    Sep 19, 2006
  4. J.L.Cooper

    Golf Competitions

    J.L.Cooper, Nov 12, 2004, in forum: C Programming
    Replies:
    9
    Views:
    388
    Merrill & Michele
    Nov 16, 2004
  5. luser- -droog

    any tricks to golf this code further?

    luser- -droog, Aug 3, 2011, in forum: C Programming
    Replies:
    7
    Views:
    958
    Moshbear dot Net
    Sep 11, 2011
Loading...

Share This Page