A scalar variable is a variable in Perl in which we can store exactly one item- a line of input,a piece of text,a number etc.
The name of a scalar variable starts with a dollar ($) sign followed by at least one letter which is followed by any number of digits or letters or underscore (_) sign.
For ex
$x
$var
$var1
$v_1_3_w
all are valid examples of scalar variables.
For ex
var
12
$12
$_
are not valid examples of scalar variables.
We can assign values to these variables by using assignment operator (=).
As $var=10;
here value 10 is assigned to variable $var.
These variables can be of any length.
$this_is_really_a_very_very_very_long_variable
is a valid variable.
The variables are case sensitive in Perl
means $var and $Var are different scalar variables.
Here is a simple program
#!/perl64/bin/perl
$scalar_variable=10;
print("The value of scalar variable is ", $scalar_variable);
The name of a scalar variable starts with a dollar ($) sign followed by at least one letter which is followed by any number of digits or letters or underscore (_) sign.
For ex
$x
$var
$var1
$v_1_3_w
all are valid examples of scalar variables.
For ex
var
12
$12
$_
are not valid examples of scalar variables.
We can assign values to these variables by using assignment operator (=).
As $var=10;
here value 10 is assigned to variable $var.
These variables can be of any length.
$this_is_really_a_very_very_very_long_variable
is a valid variable.
The variables are case sensitive in Perl
means $var and $Var are different scalar variables.
Here is a simple program
#!/perl64/bin/perl
$scalar_variable=10;
print("The value of scalar variable is ", $scalar_variable);
Output:
The value of scalar variable is 10
0 comments:
Post a Comment