Sigils

S

sinister

I'm using perl5, not perl6.

Does anyone know a pointer to an essay on perl's sigils? I've got the Camel
book, which goes over these things, but I'm looking for a discussion of the
general rationale. That is, a more abstract set of rules that would allow
me to interpret sigils without looking up meaning on a case-by-case basis.

One example: what general principle would allow one to interpret
%$a
conclude that
$array[1]
is correct but
@array[1]
isn't, and so forth.

TIA,

S
 
A

A. Sinan Unur

Does anyone know a pointer to an essay on perl's sigils? I've got the
Camel book, which goes over these things, but I'm looking for a
discussion of the general rationale. That is, a more abstract set of
rules that would allow me to interpret sigils without looking up
meaning on a case-by-case basis.

One example: what general principle would allow one to interpret
%$a

%$a is a hash, therefore $a must be a reference to a hash,
conclude that
$array[1]
is correct but
@array[1]
isn't, and so forth.

A specific element of an array is a scalar, so $array[1] is correct, and
@array[1] is not.

Have you actually considered reading the docs available on your system?

perldoc perldata

Sinan
 
I

it_says_BALLS_on_your_forehead

sinister said:
I'm using perl5, not perl6.

Does anyone know a pointer to an essay on perl's sigils? I've got the Camel
book, which goes over these things, but I'm looking for a discussion of the
general rationale. That is, a more abstract set of rules that would allow
me to interpret sigils without looking up meaning on a case-by-case basis.

One example: what general principle would allow one to interpret
%$a
conclude that
$array[1]
is correct but
@array[1]
isn't, and so forth.

i sort of view the sigils as a form of Hungarian notation, except they
are shorter, better, and more intuitive. for your example with
<sigil>array[1], the way i look at it is thusly:

if you want the element in the first index of an array, you want a
scalar. the '$' sigil looks like an 'S' for scalar. that was
purposeful.

if you want an array slice (a list of elements from an array, that you
may want to capture into another array), you would use the latter
notation. '@' looks like an 'a', for array.

i find these to be handy mnemonics, and they will become 2nd nature to
you very quickly.

the hash sigil '%', was selected, i believe, due to the percent sign's
representation of 'one element to another element'.
 
A

axel

it_says_BALLS_on_your_forehead said:
sinister wrote:
i sort of view the sigils as a form of Hungarian notation, except they
are shorter, better, and more intuitive. for your example with
<sigil>array[1], the way i look at it is thusly:
if you want the element in the first index of an array, you want a
scalar. the '$' sigil looks like an 'S' for scalar. that was
purposeful.

A useful mnemonic possibly for those strating out in Perl who have
no background in unix. However I don't think that $ was chosen
because it looks like 'S'... it was simply adopted from the
standard Bourne shell method of denoting variables.

Axel
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top