# Perl | Scalars

A scalar is a variable that stores a single unit of data at a time. The data that will be stored by the scalar variable can be of the different type like string, character, floating point, a large group of strings or it can be a webpage and so on.

Example :

 `# Perl program to demonstrate  ` `# scalars variables ` ` `  `# a string scalar ` `\$name` `= ``"Alex"``; ` ` `  `# Interger Scalar ` `\$rollno` `= 13; ` ` `  `# a floating point scalar ` `\$percentage` `= 87.65; ` ` `  `# to display the result ` `print` `"Name = \$name\n"``; ` `print` `"Roll number = \$rollno\n"``; ` `print` `"Percentage = \$percentage\n"``; `

Output :

```Name = Alex
Roll number = 13
Percentage = 87.65
```

#### Numeric Scalars

Numeric scalar variables hold values like whole numbers, integers(positive and negative), float(containing decimal point). The following example demonstrates different types of numerical scalar variables in perl.

Example :

 `# Perl program to demonstrate various types ` `# of numerical scalar variables ` ` `  `# Positive interger numerical  ` `# scalar variables ` `\$intpositive` `= 25; ` ` `  `# Negative interger numerical  ` `# scalar variables ` `\$intnegative` `= -73; ` ` `  `# Floating point numerical  ` `# scalar variables ` `\$float` `= 23.5; ` ` `  `# In hexadecimal form ` `\$hexadec` `= 0xcd; ` ` `  `# to display the result ` `print` `"Positive Integer = \$intpositive\n"``; ` `print` `"Negative Integer = \$intnegative\n"``; ` `print` `"Floating Point = \$float\n"``; ` `print` `"Hexadecimal Form = \$hexadec\n"``; `

Output :

```Positive Integer = 25
Negative Integer = -73
Floating Point = 23.5
```

#### String Scalars

String scalar variables hold values like a word(made of different characters), a group of words or a paragraph. The following example demonstrates different types of string scalar variables.

Example :

 `# Perl program to demonstrate various types ` `# of string scalar variables ` ` `  `# String scalar ` `\$alphastring` `= ``"GeeksforGeeks"``; ` `\$numericstring` `= ``"17"``; ` `\$alphanumeric` `= ``"gfg21"``; ` ` `  ` `  `#special character in string scalar ` `\$specialstring` `= ``"^gfg"``; ` ` `  `# in single quotes ` `\$singlequt` `= ``'Hello Geeks'``; ` ` `  `# To display the result ` `print` `"String with alphabets = \$alphastring\n"``; ` `print` `"String with numeric values = \$numericstring\n"``; ` `print` `"String with alphanumeric values = \$alphanumeric\n"``; ` `print` `"String within Single quotes = \$singlequt\n"``; ` `print` `"String with special characters = \$specialstring\n"``; `

Output :

```String with alphabets = GeeksforGeeks
String with numeric values = 17
String with alphanumeric values = gfg21
String within Single quotes = Hello Geeks
String with special characters = ^gfg
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.