- Perl Basics
- Perl Home
- Perl Basic Syntax
- Perl Data Types
- Perl Variables
- Perl Scalars
- Perl Arrays
- Perl Hashes
- Perl If-Else
- Perl Loops
- Perl Operators
- Perl References
- Perl Subroutines
- Perl Formats
- Perl Date & Time
- Perl File I/O
- Perl Advanced
- Perl Directory
- Perl Regular Expressions
- Perl Special Variables
- Perl Socket Programming
- Perl Send E-mail
- Perl Object Oriented
- Perl Error Handling
- Perl CGI Programming
- Perl Database
- Perl Packages & Modules
- Perl Process Management
- Perl Test
- Perl Online Test
- Give Online Test
- All Test List
Perl Scalars
A scalar in perl, is simply a single unit of data, that might be an integer number, a character, a string, or a floating-point, etc. Here is an example.
#!/usr/bin/perl $name = "Deepak"; # this is a string assignment $age = 19; # this is an integer assignment $branch = "CSE"; # this is also a string assignment print("Name = $name\n"); print("Age = $age\n"); print("Branch = $branch\n");
Here is the sample output of the above perl program:
Name = Deepak Age = 19 Branch = CSE
Numeric Scalars in Perl
Here is an example uses some numeric scalars in perl:
#!/usr/bin/perl $integer_number = 40; $negative_integer_number = -40; $floating_number = 40.340; print("Integer Number = $integer_number\n"); print("Negative Integer Number = $negative_integer_number\n"); print("Floating-point Number = $floating_number\n");
Here is the sample output of the above perl program:
Integer Number = 40 Negative Integer Number = -40 Floating-point Number = 40.34
String Scalars in Perl
Here is an example uses, some string scalars in perl:
#!/usr/bin/perl $str1 = "I am a string scalar"; $str2 = 'I am also a string, inside a single quote - $str1'; $str3 = "I am too a string, inside a double - $str1"; print("str1 = $str1\n"); print("str2 = $str2\n"); print("str3 = $str3\n");
Here is the sample output of the above perl program:
str1 = I am a string scalar str2 = I am also a string, inside a single quote - $str1 str3 = I am too a string, inside a double - I am a string scalar
« Previous Tutorial Next Tutorial »