Perl: Variables

In Perl, we need not decalare a varibale type. Meaning a variable can hold both a string or a number. All the variables in perl are preceded by a $ sign as follows: $name="david"; Again, just perl does not care about the type, you can simply reassign it to a number: $name=0; You can perform operations now: $name++; Perl can accept numbers as strings and perform arithmetic operations:

#!/usr/local/bin/perl $name='99'; $name++; print $name;

The above program would give 100 as the output. Variables in perl are case-sensitve and therefore, $name and $Name are different. Variable name can consist of numbers, letters and underscores. It should not start with a number.

Post your Answer

  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options