Sigils

Discussion in 'Perl Misc' started by sinister, Feb 26, 2006.

  1. sinister

    sinister Guest

    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
     
    sinister, Feb 26, 2006
    #1
    1. Advertising

  2. "sinister" <> wrote in
    news::

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

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Feb 26, 2006
    #2
    1. Advertising

  3. 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'.
     
    it_says_BALLS_on_your_forehead, Feb 26, 2006
    #3
  4. sinister

    DJ Stunks Guest

    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
     
    DJ Stunks, Feb 26, 2006
    #4
  5. sinister

    Guest

    it_says_BALLS_on_your_forehead <> 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
     
    , Feb 27, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page