Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Sigils

Reply
Thread Tools

Sigils

 
 
sinister
Guest
Posts: n/a
 
      02-26-2006
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


 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      02-26-2006
"sinister" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> 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 <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

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

 
Reply With Quote
 
 
 
 
it_says_BALLS_on_your_forehead
Guest
Posts: n/a
 
      02-26-2006

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'.

 
Reply With Quote
 
DJ Stunks
Guest
Posts: n/a
 
      02-26-2006

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

 
Reply With Quote
 
axel@white-eagle.invalid.uk
Guest
Posts: n/a
 
      02-27-2006
it_says_BALLS_on_your_forehead <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments