For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2006 > Sigils









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Sigils
sinister

2006-02-26, 7:55 am

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. Sinan Unur

2006-02-26, 7:55 am

"sinister" <sinister@nospam.invalid> wrote in
news:HPydnRPV2-0_NZzZRVn-ig@comcast.com:

> 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

--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/c...guidelines.html

it_says_BALLS_on_your_forehead

2006-02-26, 7:55 am


sinister wrote:
> 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'.

DJ Stunks

2006-02-26, 6:56 pm


sinister wrote:
> I'm using perl5, not perl6.


ooh-kay

> conclude that
> $array[1]
> is correct but
> @array[1]
> isn't


perldoc -q '@array'

-jp

axel@white-eagle.invalid.uk

2006-02-26, 9:56 pm

it_says_BALLS_on_your_forehead <simon.chao@gmail.com> wrote:
> 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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com