SoFunction
Updated on 2025-04-12

perl simple variable integer floating point string

Basically, a simple variable is a data unit, which can be a number or a string.
1. Integer
1. Integer
The most commonly used simple variables for PERL are basically the same as other languages, so I won't go into details.
Example:
   $x = 12345;
   if (1217 + 116 == 1333) {
   # statement block goes here
   }
Restrictions on integer types:
PERL actually stores integers in floating point registers in your computer, so it is actually treated as floating point numbers. In most computers, floating point registers can store about 16 digits, and those longer than that are discarded. Integers are actually special cases of floating point numbers.
2. Eight and hexadecimal numbers
The 8-digit starts with 0, and the hexadecimal starts with 0x.
Example: $var1 = 047; (equal to 39 in decimal)
$var2 = 0x1f; (equal to 31 in decimal)
2. Floating point number
Such as 11.4, -0.3, .3, 3., 54.1e+02, 5.41e03
Floating point registers usually cannot accurately store floating point numbers, resulting in errors. Pay special attention to operations and comparisons. The index ranges usually range from -309 to +308.
Example:

  #!/usr/local/bin/perl
  $value = 9.01e+21 + 0.01 - 9.01e+21;
  print ("first value is ", $value, "\n");
  $value = 9.01e+21 - 9.01e+21 + 0.01;
  print ("second value is ", $value, "\n");

  ---------------------------------------------------------

  $ program3_3
  first value is 0
  second value is 0.01
3. String
Programmers who are idiotic to C should note that in PERL, the end of the string does not contain implicit NULL characters, and NULL characters can appear anywhere in the string.
. Simple variable substitution is supported in strings in double quotes, for example:
  $number = 11;
  $text = "This text contains the number $number.";
Then the content of $text is: "This text contains the number 11."

.Support escape characters in strings in double quotes
Table 3.1. Escape sequences in strings.