i.) $ - The variable becomes a scalar variable which can hold one value only
ii.) @ - The variable becomes an array variable which can hold a list of scalar variables
iii.) % - The variable becomes a hash variable which stores values as key-value pairs
When used gives out warnings about the possible interpretation errors in the script.
Strict is a pragma which is used to force checks on the definition and usage of variables, references and other barewords used in the script. This can be invoked using the use strict command. If there are any unsafe or ambiguous commands in the script, this pragma stops the execution of the script instead of just giving warnings.
When used, switches on taint checking which forces Perl to check the origin of variables where outside variables cannot be used in system calls and subshell executions.
Subroutines are named blocks of code that accept arguments, perform required operation and return values. In PERL, the terms subroutine and function are used interchangeably. Syntax for defining subroutine: sub NAME or sub NAME PROTOTYPE ATTRIBUTES to be specific where prototype and attributes are optional. PROTOTYPE is the prototype of the arguments that the subroutine takes in and ATTRIBUTES are the attributes that the subroutine exhibits.
b.) Perl one-liner
One-liners are one command line only programs (may contain more than one perl statements) that are used to accomplish an operation. They are called so because the program can be typed and executed from the command line immediately.
# run program, but with warnings
perl -w my_file
# run program under debugger
perl -d my_file
Lists are special type of arrays that hold a series of values. Lists can either be explicitly generated by the user using a paranthesis and comma to separate the values or can be a value returned by a function when evaluated in list context.
An ivalue is a scalar value that can be used to store the result of any expression. Ivalues appear in the left hand side of the expression and usually represents a data space in memory.
Situation: You want to concatenate strings with Perl. How would you do that?
By using the dot operator which concatenates strings in Perl.
Eg. $string = “My name is”.$name
- Use use the libwww-perl library, LWP.pm
$url = get 'http://www.DevDaily.com/';
Perl supports access to all of the major database systems through a number of extensions
provided through the DBI toolkit, a third-party module available from CPAN. Under Windows you can use either the DBI interfaces or the Win32::ODBC toolkit, which provides direct access to any ODBC-compliant database including SQL Server database products.
my $dbh = DBI->connect(DSN);
$database = new Win32::ODBC("DSN" [, CONNECT_OPTION, ...]);