Search code examples
perlvariables

Why do Perl variables need to start with $, %,@ (sigils)?


Why do Perl variables need to start with different characters (sigils)?

  • Scalar variables start with $

  • Hashes start with %

  • Arrays start with @

Why are they like this?


Solution

  • When I started out using Perl it was explained to me that these characters were chosen because:

    • $ looked a bit like an 's' so that was for scalars,
    • @ has an 'a' in the middle so that was for arrays, and
    • % was for hashes because it looked like a key-value pair divided by a slash.