תקרת אורך מזהה (Identifier too long)#
ניסוח המקור#
perl5-upstream/pod/perlvar.pod קובע, בקטע Syntax of Variable Names:
שמות משתנים ב־Perl יכולים להיות בפורמטים מספר. בדרך כלל, עליהם להתחיל באות או קו תחתון, ובמקרה זה הם יכולים להיות באורך שרירותי (עד מגבלה פנימית של 251 תווים) ועשויים להכיל אותיות, ספרות, קווים תחתונים, או הרצף המיוחד
::או'.
This wording is wrong on three counts: the number, the unit, and the suggestion that the limit is soft.
תיקון#
The correct statement, as of the Perl 5.44 stable series, is:
Identifiers may be up to 1019 bytes long. Names exceeding this length cause a parse-time error:
Identifier too long.
Three things to take from this:
1019, not 251. Perl 5.44 sizes the parser’s token buffer from
PERL_IDENTIFIER_LENGTH(parser.h), defined as256 * MAX_UNICODE_UTF8_BYTES= 1024 bytes.S_parse_identreserves the sigil byte, the trailingNULand a margin, leaving 1019 bytes of name proper.The 251-character figure in the pod describes Perl 5.42 and earlier, where the same buffer was a flat
tokenbuf[256]. The buffer was widened by commit8785c114b5(”parser.h Allow up to 256 characters in a token“, 2025-09-28) and given its name by9bc8cdede1(”Add #define for the maximum Perl identifier length“, 2025-10-11). Both are inv5.44.0. The pod text was not updated and is now stale.Bytes, not characters. The cap is measured in bytes of the source representation, not in Unicode code points. UTF-8 identifiers therefore reach the limit at fewer characters, and a name is rejected as soon as a character’s end crosses the bound:
רוחב תו
התקבל אחרון
נדחה ראשון
1 בית (ASCII)
1019 chars = 1019 B
1020 chars = 1020 B
2 בתים (למשל
é)509 chars = 1018 B
510 chars = 1020 B
3 bytes (e.g.
ㄅ)339 chars = 1017 B
340 chars = 1020 B
4 בתים (למשל
𐌰- גותית)254 chars = 1016 B
255 chars = 1020 B
The ”characters“ in the upstream text is correct only for the ASCII case, where bytes and characters coincide.
שגיאה קשה, לא ”מגבלה פנימית“. הניסוח ”עד מגבלה פנימית“ מרמז על משהו רך. זה לא - מנתח התחביר של perl5 מעלה חריגה פטאלית
Identifier too long. ההודעה היא הדבר היחיד שהמשתמש רואה; אין קיצוץ, אזהרה, או נסיגה.
pperl behavior#
pperl matches upstream Perl 5.44 exactly at every boundary in the table above, for ASCII and for 2-, 3- and 4-byte UTF-8 identifiers alike. There is no divergence to report.
הערה
An earlier revision of this page claimed pperl diverged here by accepting names between 252 and 1019 bytes. That claim was an artifact of measuring against a Perl 5.42 binary while labelling it 5.44. Both perl 5.44 and pperl accept those names. The comparison baseline, not pperl, was wrong.
בדיקות#
בדיקות התאימות המכסות errata זה נמצאות ב:
t/01-parsing/090-identifier-length-ascii.tt/01-parsing/091-identifier-length-utf8.t
They probe the boundary at 1019/1020 bytes for ASCII and for each UTF-8 character width, plus a byte-versus-character discriminator (600 two-byte characters: only 600 characters, but 1200 bytes, so rejected) and lengths far past the cap.