@variables
A variable is defined by the ($) symbol (scalar)
the (@) symbol (arrays)
the (%) symbol (hashes)
Scalar variables are simple variables containing only one element--a string, a number, or a reference
Strings may contain any symbol, letter, or number.
Numbers may contain exponents, integers, or decimal values.
The bottom line here with scalar variables is that they contain only one single piece of data
Arrays contain a list of scalar data (single elements).
Hashes are complex lists with both a key and a value part for each element of the list.
Reference:
http://www.tizag.com/perlT/perlvariables.php
$a=1;
($a,$b)=(7,8);
$nummer1 =3;
$string1="estamboel";
print "$string1 $nummer1 \n";
print "$string1 + $nummer1 \n";
Reference:
http://www.youtube.com/watch?v=y25VxNiGc2M&feature=autoplay&list=PLE7511681ABEA8635&playnext=2
@syntax
File names, variables, and arrays are all case sensitive
'#' sign. Any words, spaces, or marks after a pound symbol will be ignored
use the backslash (\) character to escape any type of character that might interfere with our code
@strings
There is no limit to the size of the string, any amount of characters
string can be used with single or double quotations
@numbers
Numbers exist as real numbers, float, integers, exponents, octal, and hexidecimal numbers
@arrays
sequential number arrays
Rather than typing out each element when counting to 100 for example
@100 = (1 .. 100);
finding the length of an array
set the array to a scalar variable, then just print the new variable
@nums = (1 .. 20);
$nums = @nums;
adding and removing elements
push() - adds an element to the end of an array.
unshift() - adds an element to the beginning of an array.
pop() - removes the last element of an array.
shift() - removes the first element of an array.
Function Definition
push(@array, Element) Adds to the end of an array
pop(@array) Removes the last element of the array
unshift(@array, Element) Adds to the beginning of an array
shift(@array) Removes the first element of an array
delete $array[index] Removes an element by index number
No comments:
Post a Comment