Re: Very quick question about names in perl
by Abigail-II (Bishop) on Dec 15, 2003 at 12:45 UTC
|
For variables names that can be made lexical (that is, a 'my'
can be put in front of it), names start with letters or
underscore. Can't start with digits.
Package variables can consist of anything, as long as you
write them in the form: ${"..."}. Otherwise, they have to
start with letters or underscore (just like lexicals), *or*
consist of a single punctuation character, *or* consist of
numbers only. That is, $117 is a legal variable (but it's
read-only), @117 is legal, but $17foo is not.
Abigail | [reply] |
|
|
Thanks, but this raises more questions. What I plan on using this with, is to call functions that are part of an object, that will be read via $AUTOLOAD--would I be able to do something silly like $client->12('blah'), or would that be doing evil things?
| [reply] |
|
|
This is getting dangerously close to a philosphical discussion, but if you keep things simple, you'll have fewer things to worry about, and are therefore less likely to make mistakes. Speaking personally, I would limit myself to variables starting with letters and containing only letters, underscores and numbers. It makes the code easier to read (in theory), and you will spend less time later being confused. Assuming, of course, you are as easily confused as I am.
--
tbone1
Ain't enough 'O's in 'stoopid' to describe that guy.
- Dave "the King" Wilson
| [reply] |
|
|
|
|
$client -> "12" ('blah');
ought to work, but I don't have time right now to check.
Abigail | [reply] [d/l] |
|
|
There are also some special package variables like $^X. All of the ones that I know of, though, have established internal meanings.
| [reply] [d/l] |
|
|
Those are usually considered to be punctuation variables
as well.
Abigail
| [reply] |
|
|
|
|
|
|
Re: Very quick question about names in perl
by Ninthwave (Chaplain) on Dec 15, 2003 at 12:50 UTC
|
Update:I mis cut and pasted the main link.
Perl Documentation:perlvar
and the quote from it but it sums itself up well.
From: Perl Documentation: perldata
Names
Names that start with a digit may contain only more digits. Names that do not start with a letter, underscore, digit or a caret (i.e. a control character) are limited to one character, e.g., $% or $$. (Most of these one character names have a predefined significance to Perl. For instance, $$ is the current process id.)
From: Perl Documentation: perl
Bugs
While none of the built-in data types have any arbitrary size limits (apart from memory size), there are still a few arbitrary limits: a given variable name may not be longer than 251
"No matter where you go, there you are." BB
| [reply] |
|
|
# 007 (octal) is ASCII bell
perl -e '${"\00717foo"} = 1; print ${"\00717foo"}'
Though this should usually not be confused with a good idea.
---- I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer
: () { :|:& };:
Note: All code is untested, unless otherwise stated
| [reply] [d/l] [select] |
|
|
| [reply] |
|
|
If possible, I would upgrade to version 5.8.x -- that's the current version, and one that most folk would assume you are using (unless you say otherwise). The most recent release is here and many other places around and about.
--t. alex
Life is short: get busy!
| [reply] |
|
|