|
|
Types |
|
|
There are only three different types of variables in PERL: Scalar -- These variables can have any value in them (if you don't know what I'm talking about you probably don't need to). Array -- This is a set of variables all rolled into one happy variable. Associative Array -- This is an array that uses easy to remember names for it's elements(the values in the array). |
|
| We will now go over each type of variable individually. |
Scalars | |
| This is the easiest variable to use. It is a word or letter that you choose which has a number value(such as 5), a character value(such as 'a'), or a string value(such as "a cat"). | |
| To use this you would type $nameOfVariable = 234;. FYI: Almost all statements end with a semicolon(;)! |
Arrays | |
| The <HEAD> tag has all the An array can be really useful for databases or for reading a file into memory. | |
| You declare an array by using an at sign(@) | |
| Such as: @snark = ("21"," set,"," snark!"); | |
| To get the first value you would type $snark[0], the second would be $snark[1], the third being $snark[2]. |
Associative Arrays | |
| Associative arrays allow the programmer to reffer to different elements by names instead of numbers | |
|
For example: %gorp = ("hobby","programming","gender","male"); would set the value of $gorp{'hobby'} to "programming" |
Using the variable |
|
Open a text editer and type: @turtle = (4.5,4.2,"narf","zonk","5th element"); %gorp = ("hobby","programming","gender","male"); print("$gorp{'hobby'}"); $usersaid = print("$usersaid"); foreach $glerb (@turtle) { print("gerbil $glerb "); } |
| Now we're getting into loops! |
|
|
|