Last week, we wrote our first PERL script and we got introduced to scalar variables. A scalar variable will store exactly one item, like it can store one number or a string or a line of standard input.
An important thing is how you name the scalar variable or the syntax.
- It cannot start with a number. $2ac, $5 is illegal
- It cannot have any special character.$abc@, $dff! Is illegal
- It should either start with an alphabet or a _. $a_, $_a, $a are legal
- You can have a very long name. $This_is_a _long_name is legal.
- $hi, $HI, $hI are all different variables; means its case sensitive.
There is this function called chop. As the name suggests, it chops the right most character of a string or the trailing newline.
Conditional Statements Syntax:
The PERL interpreter executes through if-elsif-else only once when it encounters it.
But it is different for while and until statements.
while loops gets executed until the conditional expression remains TRUE.
until loop gets executed while the conditional expression remains FALSE.