perl sigils

Perl uses sigils to indicate the context and type of variables. Sigils are special characters that are placed at the beginning of variable names. Here are the sigils used in Perl:

  • $ (Scalar sigil): It denotes a scalar variable, which can hold a single value such as a number, string, or reference.

  • @ (Array sigil): It denotes an array variable, which can hold an ordered collection of values.

  • % (Hash sigil): It denotes a hash variable, which can hold a collection of key-value pairs.

  • & (Subroutine sigil): It denotes a subroutine variable, which can hold a reference to a subroutine.

Here are some examples:

  • Scalar variable: $name = "John";

  • Array variable: @numbers = (1, 2, 3);

  • Hash variable: %person = ('name' => 'John', 'age' => 25);

  • Subroutine variable: $sub = \&some_subroutine;

These sigils help Perl in distinguishing between different types of variables and provide context for their usage.