Beruflich Dokumente
Kultur Dokumente
Reference: teach_yourself_perl_in_21_days.pdf
Operators: Exponential: $var = $a ** $b, Treat as a power of b. Remainder: $var = $a % $b, It assigns remainder of a/b to $var. Comparison: $var = $a == $b, It assigns 1 to $var if $a equal $b. >(gt), <(lt), <=(le), >=(ge), !=(ne), ==(eq) operators are used. Logical: ||(or), &&(and), !(not), xor. Bitwise: &(AND), |(OR), ^(XOR), ~(NOT), <<(Left shift), >> (Right shift). Assignment: =, +=, -=, *=, /=, %=, **=, &= String concatenation and repetition: Concatenation: $str1 = ab, $str2 = cd, $res = $str1 . $str2, $res = abcd. Repetition: $str1 = a x 5, $str1 becomes aaaaa, Conditional operator and left side assignment: $result = ($var1 == 1) ? $str1 : $str2 . $var1 == 1 ? $str1 : $str2 = Hello.
List operations: @array = (this, is, a, string); $string = join (::, @array); $string = this::is::a::string. @array = split(/::/, $string); @array = (this, is, a, string);
File-Test Operator: If (-X string) where -X: -d checks, Is string directory ? -e checks, Does string name is exist ? -r checks, Is string named file readable ? -w checks, Is string named file writable ? -x checks, Is string named file executable ? -z checks, Is string named file empty ? -s checks the size of the file.
For loop: Syntax example: for ($i=0; $i<value; $i++) { expression } This loop will execute expression for value times. Foreach loop: Syntax example: foreach $i (@array) { expression } Each element of the @array will assign to $i and execute expression for each element of the @array. Do statement: Syntax example: do {exp} while_or_until (cond) It executes the expression till condition in while or until loop goes wrong. Last statement: Syntax: last if (cond) ; Execution comes out from while/until/for/do loop if condition true. Next statement: Syntax: next if (cond); Execution goes to next iteration of while/until/for/do loop if condition true.
Execution thread jump to label where it find. Label can be any name.
rewinddir (DIR): This function sets the current directory location to the beginning of the list of the files, which start to read again from start. rmdir (DIR): It removes the directory handled by DIR. rename (oldname, newname): This function removes the oldname file to newname. chmod (permission, filelist): This function sets the permission of files listed in argument.
Mathematical functions: sin ($radvalue): This function returns the sine value. cos ($radvalue): This function returns the cosine value. To convert degree value to radian: $radval = atan2 (1, 1) * $degree / 45 ; sqrt (value): This function returns the square root of value. abs (value): Returns the absolute value of the value. rand (value): Randomizes the integer between range 0 to value. srand (value): It takes the value as a random number seed.
String manipulation functions: index (string, the): It searches the from the entered string and returns the index of the starting of the searched string. rindex (string, the): It searches the starts from the right end of the string. length (string): It returns the length of the passed string. substr (expr, skipchars, length): expr contains string, skipchars is the number of character to skip from extr. Length is number of the characters after the skipchars to be returned by this function. Join and split are also string manipulation functions.
Array and List Functions: grep (pattern, list): It greps the pattern from the list. splice (array, skipelements, len, newlist): It skips the element specified by the skipelements from array and replaces the len number of elements by newlist. By the use of splice, we can replaces the list elements from array, Appending the list elements, Deleting list elements. shift (array): It removes the last element from the left, moves other elements to left and returns removed elements. push (array, elements): It adds the element to the end of list. pop (array): It removes the last element from a array and returns the removed elements. sort (array): It sorts an array elements in alphabetical order. reverse (array): It reverses the order of the list.
Thank you