Search⌘ K

Solution Review: Make Variables

Explore how to declare and initialize different Perl variables including integers, characters, booleans, and floating-point numbers. Learn to use the print statement and concatenation operator to display variable values, preparing you to effectively handle Perl variable types in your programs.

We'll cover the following...

Let’s have a look at the solution before jumping onto the solution:

Perl
$intNumber = 1000;
$charName = 'N';
$boolAccept = 1;
$floatNum = 10.292;
print $intNumber . ", ";
print $charName . ", ";
print $boolAccept . ", ";
print $floatNum;

Explanation

We have declared:

  • an integer type variable $intNumber and assigned it a value of 1000

  • a character type variable $charName and assigned it a value of ‘N’

  • a boolean type variable $boolAccept and assigned it a value of 1

  • a floating type variable $floatNum and assigned it value of 10.292

After declaring the variables, we used the print statement to display them and we have used . operator to concatenate the , with the result.