in reply to Re^2: PERL Variable Name, Significant length
in thread PERL Variable Name, Significant length

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.
RIP PCW

Replies are listed 'Best First'.
Re^4: PERL Variable Name, Significant length
by morgon (Priest) on Aug 07, 2009 at 23:38 UTC
    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...

      Checking more closely, it appears to be 255 including the sigil on my system. (Vista 64/AS 5.10.4 64-bit.)

      If you're sure it is different on your system, maybe the limitation is some CRT internal static buffer that varies with compiler?


      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.
        Here is what I do:

        perl -e 'print "\$" . "x" x 257 . " = 1"' > 257.pl perl 257.pl
        This does not give an error. However:

        perl -e 'print "\$" . "x" x 258 . " = 1"' > 258.pl perl 278.pl Identifier too long at 258.pl line 1.
        So it seems that on my system (32-bit Ubuntu) 257 is indeed the limit ... very strange though that this should be platform-dependent.