TimeLinux1

Tuesday, April 12, 2011

Linux: Perl - 2

... continued ...

-Perl has designed to be close to human languages.
-For instance, perl distinguishes between singular and plural data
-also, perl 'say' cmd is like print but adds a newline and sounds more natural.
-In Perl, a variable comes into existence when you assign value to it--no need to declare first.
-But if you want, you can use 'use strict' clause to require explicit declaration.
-also, you refer the variable each time with the identifiers $ (scalar), @ (array) or % (hash)
-when you define variable with a lexical term 'my' it is recognized only within that program (ie local scope).
-this is useful when you have many subroutines and each needs local scope definition to not interfere with others.
-scalar variables begin with $ sign and hold a string or number.
-eg: $name = "Sammy" or $n1 = 5;
-Perl is smart enough to determine from context if a scalar is string or number.
-running a perl prog with -w shows runtime warnings, if any.
-running a perl prog with -e checks syntax on the command line.
-array variables hold multiple scalars.
-eg: @arrayvar = (8, 18, "Sammy"). It is a plural variable.
-hash variable is a plural variable that holds an array of key-value pair.n
-hashes are unordered, you need not have a sequence and can miss a key (eg 0 1 3 instead of 0 1 2 3).
-eg: %hashvar = (boat => seastar, numfive =>5, 4=>fish);
-in the above, the first element is boat, 2nd is numfive and third is 4 (a numeric).
-so the elements were 2 string types and one numeric, ie no order or same type reqd; thats hash.
.
.. continued ...

No comments:

Post a Comment