Perl - Variables
In a Nutshell - CIW Course Section 2, Part B1, Chapter 2
Variables
Perl is a loosely-typed language, which means that you do not need to declare variables as specific data types. A scalar variable is the fundamental data type in Perl and stores a single value. The scalar variable may be a numeric or a string type, but only assumes this type when a value is assigned to it. The scalar variable is identified by prefixing the name with the $ (dollar symbol).
A variable is initialised when a value is assigned to it. It is at this point that it will assume the numeric or string data type.
Unlike other programming and scripting languages, Perl variables are global in scope unless explicitly declared otherwise. More on this in a later chapter.
| $newString = "Hello World"; $newNumeric = 100; |
User Input
<STDIN> is a filehandle, but it does not read from a file. Instead it reads input from the keyboard. When the <STDIN> filehandle is encountered program execution pauses, awaiting keyboard input. Keypresses are read until the ENTER key is pressed.
| $keyInput = <STDIN>; chomp ($keyInput); |
Whatever is typed at the keyboard will be assigned to the variable $keyInput, this will be terminated with the "\n" newline character.
The chomp function will strip the newline character from the variable.

