in reply to PERL Variable Name, Significant length

Perl variable names can have any number of characters and they are all significant.

But if you are intending using varible names much more than 10 or 15 chars in length, you will be roundly cursed by those that follow you.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP PCW
  • Comment on Re: PERL Variable Name, Significant length

Replies are listed 'Best First'.
Re^2: PERL Variable Name, Significant length
by morgon (Priest) on Aug 07, 2009 at 13:04 UTC
    Perl variable names can have any number of characters and they are all significant.
    This is not true. On my 5.10.0 I get an "Identifier too long" error when the varname gets too long.

    How long variable-names can be came up in the quizz-show of this weeks YAPC::Europe and as far as I can remember it was 251 characters.

      Oh my, you appear to be correct.

      The parser seems to have a hardcoded limitation of 256 characters. This runs fine:

      C:\test>perl -E"$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1 = 1"

      But add 1 more x and it stops with:

      C:\test>perl -E"$xxxxxxxxxxxxxxxxx Identifier too long at -e line 1.

      or just traps or both. But the limitation (static buffer or hardcoded length?) is only in the parser, the rest of perl handles longer fine. What I did to verify my assertion above (before making it) was:

      $longName = 'x' x 1e4;; ${ $longName . 1 } = 1;; ${ $longName . 2 } = 2;; if( ${ $longName . 1 } != ${ $longName . 2 } ) { print 'Great! Ten thousand characters long and all significant.' };; Great! Ten thousand characters long and all significant.

      I knew there was some limitation, because when I tried for a hundred thousand(*) it bellyached about something being readonly. But as far as I'm concerned, 10,000 is for all practical purposes, unlimited.

      I've encountered one or two authors that insisted in detailing their life, work or academic career histories into their comments; but never a novella in a variable name :)

      (*)Update: Or maybe I just typoed because I've now succeeded in creating variable with a million (and one) significant characters...


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        The parser seems to have a hardcoded limitation of 256 characters.
        Hmm, on my 5.10.0 on Linux the limit seems to be 257 (which works fine, from 258 on I get an error) - a strange limit indeed...

      $How_long_variable_names_can_be_came_up_in_the_quizz_ show_of_this_weeks_YAPC__Europe_and_as_far_as_I_can_remember_ it_was_251_characters_i_am_not sure_but_I_am_guessing =251;

      This line was soooo long that it blew up the Monk server rendering engine. Readers can paste the lines together into a single line if they want, but what's the point? You get the idea!!!

      That $var name is only 167 chars long and makes my brain hurt! I have typed single command line command that long, but they are doing a lot of running this, piping that, etc...

      If you are getting "Identifier too long", I think some serious thought about naming conventions is in order!

        I just want to point out that long variable names can make very much sense in generated code - they can make quite a difference in readability, compared to short but semi-random names.