Friday, 6 July 2012

Beginner's Introduction to Perl



1. perl - practical extraction and report language

2. Created in 1987 by Larry Wall, the UNIX based language has evolved into a powerful tool for the internet. It was designed as a quick-fix patch program for UNIX based systems.

3. its popularity has increased due to its flexibility, portability, usefulness, and its varied features.

4.A PERL script can be created inside of any normal simple-text editor program.

5.a PERL file must be saved with a .pl (.PL) file extension in order to be recognized as a functioning PERL script.
File names can contain numbers, symbols, and letters but must not contain a space. Use an underscore (_) in places of spaces.


firstscript-linux.pl:

firstscript-linux.pl:

#!/usr/bin/perl

print "content-type: text/html \n\n";   ( We have to introduce some HTTP headers so that Perl understands we are working with a web browser,)
-->\n indicates the ``newline'' character; without it, Perl doesn't skip to a new line of text on its own.

print "Hello, Perl!";  (we can print text to the browser with the print function.)


:wq!


Development Tools:Download and install ActivePerl

Perl IDEYou first need to download ActivePerl the latest versionfrom http://www.activestate.com/activeperl/. The file we downloaded at the time of this tutorial being written wasActivePerl-5.10.0.1004-MSWin32-x86-287188.msi. You can also find the installation files for other systems and versions via following linkhttp://www.activestate.com/activeperl/downloads/


===>http://www.perlmonks.org/?node=Tutorials


===================
Examples:1


#where perl


#which perl


[sankar@new-host perlscript]$ vim hello.pl


#!/usr/bin/perl
#displays a warm greeting


print "Hello, SHANKAR!\n";


:wq
-----------OR-------------

#!/usr/bin/perl
# Displays a warm greeting. my $name = "Sai"; print "Hello, $name!\n";


[sankar@new-host perlscript]$ chmod +x hello.pl


OutPut:
[sankar@new-host perlscript]$ perl  hello.pl



Hello, SHANKAR!


Perl documentation documentation:

1. perldocs - Perl documentation documentation


     [root@new-host ~]# perldoc perldoc



2. perltoc - perl documentation table of contents 


   Note:(Any time you want to read a perl manual page,just tell perldoc to display that page)


     [root@new-host ~]# perldoc perltoc


3. POD is ``Plain old documentation''. the Plain Old Documentation format

      [root@new-host ~]# perldoc perlpod



You can look at the POD source with perldoc's -m switch.
    [root@new-host ~]# perldoc -m perlpod


You can convert POD to other formats, including LaTeX, HTML, and text. Look for the pod2latex, pod2html, and pod2text. You need to give it the file name to convert, which you can get with perldoc's -l switch.
       
   #pod2html `perldoc -l perl` > perl.html

4. perlfaq

There are nine perlfaq pages, broken into broad categories. perlfaq is a table of contents.



You can search the perlfaq pages with perldoc's -q switch.

        
  #perldoc -q perldoc


5. perlfunc


perlfunc lists the documentation for each perl function, and although you should read it through at least once in your life, you can read the documentation for a single function with perldoc's -f switch.

    

  #perldoc -f localtime


6. Modules

Use the perldoc command to read the documentation for installed modules.

        

  #perldoc Module::Starter


7. For instance, you can limit your search to a particular site with in a Google search. This query limits itself to perldoc.perl.org


        #perldoc site:perldoc.perl.org CGI


============================


1. what is the use of #!/usr/bin/perl other than to interpreter?

The #! line has two programs that "interpret" it:To the shell. 

An executable file that starts with a #! line will cause the executing shell to start up the program indicated in that line. 

That way, you can use #!/bin/sh to create a shell script, #!/usr/bin/perl to create a perl script etc. At least on unixish systems, there is always a shell involved in this process. 


perl reads the additional arguments on the #! line as a sort of "setup parameters". Example:#!/usr/bin/perl -wT will run perl with global warnings enabled and in taint mode.


The #! line, also called shebang,
=========================================

The basic data types, three


Perl has three basic data types:
                                           1. scalars,
                                                    2. arrays,
                                                    3. hashes.



1.Scalars

Scalars are the most basic type of data in Perl they can represent a number(int, float, whatever) or a string of text.


eg:
$a=5;
$b="five"; $c=5.0

Here's an example: (Note scalar variables begin with an $)
$a="5.0"; # set up our variables $b="5"; # # to the end of a line is a comment in perl print "Are these variables equal as numbers? ",$a==$b,"\n"; print "Are the variables equal as strings? ",$a eq $b,"\n"; print "These variables are equal as strings\n" if($a eq $b); print "These variables are equal numerically\n" if($a==$b);
Integer literals in Perl are pretty straight forward Here are some examples
143
-3
-8431
42
0



Floats in Perl can be represented in all the ways that C would allow you to
Here are some examples for you:

  0.1 
-123.4
-10e4  # (-10) times 10 to the fourth power
-10E4  # the same thing
-1E5   # Another way to say the same thing
-1e-6  # -1 * 10 to the -6th power

In perl there are two ways to represent string literals: 
                1.single-quoted strings and 
                   2.double-quoted strings.

Single-Quoted Strings:
Single quoted are a sequence of characters that begin and end with a single quote. These quotes are not a part of the string they just mark the beginning and end for the Perl interpreter. If you want a ' inside of your string you need to preclude it with a \ like this \' as you'll see below. 

Let's see how this works below.

'four'       #has four letters in the string
'can\'t'     #has five characters and represents "can't"
'hi\there'   #has eight characters and represents"hi\\there" (one \ in the string)
'blah\\blah' #has nine characters and represents "blah\\blah" (one \ in the string)
If you want to put a new line in a single-quoted string it goes something like this
'line1
line2'       #has eleven characters line1, newline character, and then line2
Single-quoted strings don't interpret \n as a newline. 


Double-Quoted Strings:
Double quoted strings act more like strings in C or C++ the backslash allows you to represent control characters. Another nice feature Double-Quoted strings offers is variable interpolation this substitutes the value of a variable into the string. 

Some examples are below

$word="hello";             #$word becomes hello
$statement="$word world";  #variable interpolation, $statement becomes "hello world"
"Hello World\n";           #"Hello World" followed by a newline

Some of the things you can put in a Double-Quoted String

RepresentationWhat it Means
\aBell
\bBackspace
\eEscape
\fFormfeed
\nNewline
\rReturn
\tTab
\\Backslash
\"Double quote
\007octal ascii value this time 007 or the bell
\x07hex ascii value this time 007 or the bell
\cDany control character.. here it is control-D
\llowercase next letter
\uuppercase next letter
\Llowercase all letters until \E
\Uuppercase all letters until \E
\QBackslash quote all nonletters and nonnumbers until \E
\EStop \U \L or \Q





2.Arrays
Arrays are basically a collection of scalars stored next to each other and accessed by indices from zero to the number of elements minus one. 



Note: when we're referring to an entire array we use the @ at the beginning of its name. If we're referring to only one of its elements(which is a scalar) we use a $.


@a=(1,2,3); @simpsonsfamily=("homer","marge","lisa","maggie","bart");


Arrays can store either strings or numbers or both. Now lets see how we can get at an individual element of an array.

$a[0]; #This returns the first element in @a which is 1
$simpsonsfamily[4]; #This returns the fifth element which is bart
$a[3]=4; #This sets the 4th element in @a to 4.

Note:One nice thing about arrays in Perl is that you don't have to set the size of them when you start so they will grow for you when you need them to.

Some other functions I will quickly mention are push and reverse. 



push is followed by the array you want to add to, and then a value or list of values that you want added to the end. It would look something like:

push @array, $value; #puts $value onto the end of @array.
reverse function simply takes a list or array and reverses it. For example, to reverse the order of an array permanently you would just type something like:
@array=reverse @array;
Functions for real @ARRAYs
poppushshiftsplice
unshift

Functions for list data
grepjoinmapqw/STRING/reversesortunpack 




3. Hashes

Hashes are collections of scalars like arrays only they have indices or keys which are strings instead of integers. Hash variables are named with a % followed by at least one letter and then maybe a mix of some more numbers, letters, and underscores. Key and value are two important hash terms.

Now we'll show you how you can initialize and access elements of an array.


@array=("key1","value1","key2","value2"); #an array filled with key
+value pairs %hash1=("key1"=>"value1","key2"=>"value2"); #one way to initialize a h
+ash (key=>value,key2=>value2,..) %hash2=@array; #making %hash2 out of a co
+llection of key value pairs in an array $hash3{"key1"}="value1"; #creates key of "key1" and
+ value of "value1" $hash3{"key2"}="value2";
Functions for real %HASHes  deleteeachexistskeysvalues 
============================================
Context is everywhere in Perl. Every operand is evaluated in some context. Every expression is constrained by the context in which it is evaluated.
The two main contexts are 1. scalar context and 2. list context. 
Another is void.
For these examples, I'll use localtime since it's a common function which evaluates differently according to context. it returns a human readable string to describe the current time.
# Example 1. # @now will be (40, 51, 20, 9, 0, 109, 5, 8, 0) @now = localtime(); # Example 2. # $now will be "Fri Jan 9 20:51:40 2009" $now = localtime();
========================================================================

Operators

The Basic Arithmetic Opertators
ExampleTypeResult
$a+$bAdditionSum of $a and $b
$a-$bSubtractionResult of $b subtracted from $a
$a*$bMultiplicationProduct of $a and $b
$a/$bDivisionResult of $a divided by $b
$a%$bModulusRemainder when $a is divided by $b
$a**$bExponentiation$a to the power of $b

String Operators


Perl has its own addition and mulitply operators for strings. These operators are . and x respectively.
$a=2; $a=3; print $a+$b #arithmetic operator prints 5 print $a.$b #string operator prints 2 plus the three or 23 print $a*$b #arithmetic operator prints 6 print $a x $b #string operators prints $a $b times or 2 three times. i +e 222


Assignment Operators
Assignment simply set values on the left side of a = to what is on the right side. 


$a=3; $b="x"; $c=4; $a*=3; #$a=$a*3; $a now equal to 9; $a/=3; #$a=$a/3; $a (9) divided by three which equals 3; $a+=2; #$a=$a+2; $a is now equal to 5; $a-=2; #$a=$a-2; $a is now equal to 3; $b x=3; #$b=$b x $3 $b is now equal to "xxx"; $b .="33"; #b=$b."33" $b is now equal to "xxx33";


Comparison Operators:


TypeNumericString
Greater Than>gt
Less Than<lt
Equal to==eq
Not equal!=ne
Less than or equal to<=le
Greater than or equal to>=ge


Auto-increment and Autodecrement operators These operators simply add or subtract one from a given variable.


$a=1; print $a++; #prints a as one then adds 1 to it print $a; #now $a is 2 print ++$a; #adds one to $a and then prints its value which is now 3; print $a--; #prints 3 then subtracts one from $a;


Logical Operators:


ExamplesShort VersionTextual VersionMeaning
$a and $b; $a && b&&andreturns true if $a and $b are both defined and nonzero
$a or $b; $a||$b||orreturns true if either $a or $b is defined and nonzero
!$a; not $a!notreturns the opposite of what an expression would otherwise



Precedence for Idiots:

then precedence-awareness of operators probably only goes as far as knowing that 2+3*4 means2+(3*4),

5-1+2 might have you scratching your head - which has precedence - the '-' or the '+'? The answer is 'whichever comes first' - they have equal precedence but left associativity, so 5-1+2 is (5-1)+2, but 5+1-2 is (5+1)-2

For example, ** (the 'to-the-power-of' operator) has right-associativity, so 2**3**4 is 2**(2**3), not (2**2)**3.

Below is a short table that will hopefully make all of this a little clearer.

FunctionMeaning$x is now..
$x = 5 == 6 or 5 == 5($x = (5 == 6)) or ($x = (5 == 5))FALSE
$x = (5 == 6 or 5 == 5)$x = ((5 == 6) or (5 == 5))TRUE
$x = 5 == 6 ¦¦ 5 == 5$x = ((5 == 6) ¦¦ (5 == 5))TRUE
($x = 5 == 6) ¦¦ 5 == 5($x = 5 == 6) ¦¦ 5 == 5FALSE
$x = 5 ¦¦ 6 == 6$x = (5 ¦¦ (6 == 6))5
$x = (5 ¦¦ 6) == 6$x = ((5 ¦¦ 6) == 6)TRUE
$x = 5 or 6 == 6($x = 5) ¦¦ ($x = (6 == 6))5
$x = 1 == 2 && 3$x = (1 == 2) && $x = 33
$x = 1 == 2 ¦¦ 3$x = (1 == 2) ¦¦ $x = 3FALSE

What is true and false in Perl?



Well for starters "0" and an empty string("") are false. Anything else is basically true.

0 # converts to "0" so it's false; "" # is empty string so it's false; "0.0" # not "0" or "" so it's true 0.0 # computes to 0 and is then converted to "0" so false undef # evaluates to "" so it's false -- note, you may get a warni +ng "use of uninitialized value" if you are using -w 2-3+1 # computes to 0 which is converted to "0" so it is false
================================================

Flow Control Structures

Or you can dive right into the control statements




  • if statements
  • unless statements
  • while loops
  • until loops
  • do while loops
  • do until loops
  • for loops
  • foreach loops
  • 1. if statements

    if statements test a control statement to see whether it is true or false. else and elsif clauses can also be tagged on the back.

    #your basic if if($value==1){ print "value is equal to 1\n"; }
    #your basic if/else if($value==1){ print "value is equal to 1\n"; } else{ print "value is not equal to 1\n"; }
    #your basic if/elsif/else if($value==1){ print "value is equal to 1\n"; } elsif($value==2){ print "value is equal to 2\n"; } elsif($value==3){ print "value is equal to 3\n"; } else{ print "value is not equal to 1,2, or 3\n"; 
    }          


    2. unless statements

    Unless statements allow you to say unless something is true do this. For example:
    
    

    $value=20;
    unless($divisor==0){      #so long as the $divisor isn't equal to 0
      $value=$value/$divisor; #go ahead and divide $value by $divisor
    } else {
      $divisor=1;             #otherwise set $divisor to 1
    }

    
    

    
    

    3. while loops

    while loops allow you to execute a group of statements so long as a statment still evaluates to true.
    Here's a quick example;
    $num=20; while($num<30){ print "num is $num\n"; $num=$num+1; } this will print out num is 20 num is 21 ... num is 29
    4. until loops
    Until loops are just the opposite of whiles. If the control statement evaluates to false code within the loop is executed once and repeated until the control statement tests to true.
    Heres a quick example:
    
    

    $year=1900;
    until($year==2000){
       print "Mission-critical electronics working in the year $year\n";
       #now it works;
       $year++;
    }
    print "Not working anymore\n";

    
    

    5. do while loops


    while loops test the condition before every execution of the loop. Sometimes you want it to be tested after the loop.

     This guarantees that the loop is run once before the condition is tested.
    $value=5
    do{
      print "$value\n";
      $value=$value-1;
    } while($value>10);
    

    The above code prints out:
    5


    6. do until loops


    These work the same as do while loops only they execute until the condition evaluated is true
    Here's a quick example:
    
    
    $value=5;
    do{
      print "$value\n";
      $value=$value-1;
    } until($value<=10);
    


    This is executes once and prints out $value;
    5
    Then $value is decremented and becomes 4
    since 4<=10 is true execution of the loop is terminated






    7. for loops


    For loops allow you to do something a certain number of times in their most basic forms;
    They take on the form:
    
    for(initial_expression; test_expression; change_expression){
       do_something;
    }
    
    This is equivalent to a while statement that looks like
    
    initial_expression;
    while(test_expression){
       do_something;
       change_expression;
    }
    
    This for loop will print the numbers 1 through 100 on separate lines;
    
    for($i=1; $i<=100; $i++){
       print "$i\n";
    }
    
    
    
    First the variable is set to 1, then it is tested to see if it is less than or equal to 100. Then it is printed. Then the change expression is evaluated and $i is incremented by 1.

     Then the text expression is evaluated again since $i is equal to 2 it is less than or equal to 100 so the loop is repeated until 100 is printed, $i is incremented to 101, $i is no longer less than or equal to 100 so the for loop is finished. 


    8. foreach loops

    The foreach loop allows you to do something to each value in an array.
    A quick example is below:

    @numbers=(1,7,3,8,9); foreach $number(@numbers){ #makes $number point to array value; $number++; #$number is incremented by 1 which is refle +cted inside the actual array; } #Now if we print out all the numbers they should reflect our changes #ie @numbers is now equal to (2,8,4,9,10); foreach(@numbers){ #notice here we don't specify a variable so Perl us +es its default: [perlman:perlvar|$_] print "$_,"; #we print the changed numbers separated by commas }
    ==============

    Why you should use strict ?

    I strongly recommend you always load the strict module in all your programs. 
    Putting use strict; at the top of your programs will tell perl to slap your hands with a fatal error whenever you break certain rules. And just like the rules against playing on the roof or freebasing crystal meth, those rules are there to help you.
    
    
    --------------------------

    Perl Special Variables Quick Reference ?

    $_The default or implicit variable.
    @_Subroutine parameters.
    $a $bsort comparison routine variables.
    @ARGVThe command-line args.
    Regular Expressions
    $<digit>Regexp parenthetical capture holders.
    $&Last successful match (degrades performance).
    ${^MATCH}Similar to $& without performance penalty. Requires /p modifier.
    $`Prematch for last successful match string (degrades performance).
    ${^PREMATCH}Similar to $` without performance penalty. Requires /pmodifier.
    $'Postmatch for last successful match string (degrades performance).
    ${^POSTMATCH}Similar to $' without performance penalty. Requires /pmodifier.
    $+Last paren match.
    $^NLast closed paren match (last submatch).
    @+Offsets of ends of successful submatches in scope.
    @-Offsets of starts of successful submatches in scope.
    %+Like @+, but for named submatches.
    %-Like @-, but for named submatches.
    $^RLast regexp (?{code}) result.
    ${^RE_DEBUG_FLAGS}Current value of regexp debugging flags. See use re 'debug';
    ${^RE_TRIE_MAXBUF}Control memory allocations for RE optimizations for large alternations.
    Encoding
    ${^ENCODING}The object reference to the Encode object, used to convert the source code to Unicode.
    ${^OPEN}Internal use: \0 separated Input / Output layer information.
    ${^UNICODE}Read-only Unicode settings.
    ${^UTF8CACHE}State of the internal UTF-8 offset caching code.
    ${^UTF8LOCALE}Indicates whether UTF8 locale was detected at startup.
    IO and Separators
    $.Current line number (or record number) of most recent filehandle.
    $/Input record separator.
    $|Output autoflush. 1=autoflush, 0=default. Applies to currently selected handle.
    $,Output field separator (lists)
    $\Output record separator.
    $"Output list separator. (interpolated lists)
    $;Subscript separator. (Use a real multidimensional array instead.)
    Formats
    $%Page number for currently selected output channel.
    $=Current page length.
    $-Number of lines left on page.
    $~Format name.
    $^Name of top-of-page format.
    $:Format line break characters
    $^LForm feed (default "\f").
    $^AFormat Accumulator
    Status Reporting
    $?Child error. Status code of most recent system call or pipe.
    $!Operating System Error. (What just went 'bang'?)
    %!Error number hash
    $^EExtended Operating System Error (Extra error explanation).
    $@Eval error.
    ${^CHILD_ERROR_NATIVE}Native status returned by the last pipe close, backtick (`` ) command, successful call to wait() or waitpid(), or from the system() operator.
    ID's and Process Information
    $$Process ID
    $<Real user id of process.
    $>Effective user id of process.
    $(Real group id of process.
    $)Effective group id of process.
    $0Program name.
    $^OOperating System name.
    Perl Status Info
    $]Old: Version and patch number of perl interpreter. Deprecated.
    $^CCurrent value of flag associated with -c switch.
    $^DCurrent value of debugging flags
    $^FMaximum system file descriptor.
    $^IValue of the -i (inplace edit) switch.
    $^MEmergency Memory pool.
    $^PInternal variable for debugging support.
    $^RLast regexp (?{code}) result.
    $^SExceptions being caught. (eval)
    $^TBase time of program start.
    $^VPerl version.
    $^WStatus of -w switch
    ${^WARNING_BITS}Current set of warning checks enabled by use warnings;
    $^XPerl executable name.
    ${^GLOBAL_PHASE}Current phase of the Perl interpreter.
    $^HInternal use only: Hook into Lexical Scoping.
    %^HInternaluse only: Useful to implement scoped pragmas.
    ${^TAINT}Taint mode read-only flag.
    ${^WIN32_SLOPPY_STAT}If true on Windows stat() won't try to open the file.
    Command Line Args
    ARGVFilehandle iterates over files from command line (see also<>).
    $ARGVName of current file when reading <>
    @ARGVList of command line args.
    ARGVOUTOutput filehandle for -i switch
    Miscellaneous
    @FAutosplit (-a mode) recipient.
    @INCList of library paths.
    %INCKeys are filenames, values are paths to modules included via use, require, or do.
    %ENVHash containing current environment variables
    %SIGSignal handlers.
    $[Array and substr first element (Deprecated!).
    $_The default or implicit variable.
    @_Subroutine parameters.
    $a $bsort comparison routine variables.
    @ARGVThe command-line args.
    Regular Expressions
    $<digit>Regexp parenthetical capture holders.
    $&Last successful match (degrades performance).
    ${^MATCH}Similar to $& without performance penalty. Requires /p modifier.
    $`Prematch for last successful match string (degrades performance).
    ${^PREMATCH}Similar to $` without performance penalty. Requires /pmodifier.
    $'Postmatch for last successful match string (degrades performance).
    ${^POSTMATCH}Similar to $' without performance penalty. Requires /pmodifier.
    $+Last paren match.
    $^NLast closed paren match (last submatch).
    @+Offsets of ends of successful submatches in scope.
    @-Offsets of starts of successful submatches in scope.
    %+Like @+, but for named submatches.
    %-Like @-, but for named submatches.
    $^RLast regexp (?{code}) result.
    ${^RE_DEBUG_FLAGS}Current value of regexp debugging flags. See use re 'debug';
    ${^RE_TRIE_MAXBUF}Control memory allocations for RE optimizations for large alternations.
    Encoding
    ${^ENCODING}The object reference to the Encode object, used to convert the source code to Unicode.
    ${^OPEN}Internal use: \0 separated Input / Output layer information.
    ${^UNICODE}Read-only Unicode settings.
    ${^UTF8CACHE}State of the internal UTF-8 offset caching code.
    ${^UTF8LOCALE}Indicates whether UTF8 locale was detected at startup.
    IO and Separators
    $.Current line number (or record number) of most recent filehandle.
    $/Input record separator.
    $|Output autoflush. 1=autoflush, 0=default. Applies to currently selected handle.
    $,Output field separator (lists)
    $\Output record separator.
    $"Output list separator. (interpolated lists)
    $;Subscript separator. (Use a real multidimensional array instead.)
    Formats
    $%Page number for currently selected output channel.
    $=Current page length.
    $-Number of lines left on page.
    $~Format name.
    $^Name of top-of-page format.
    $:Format line break characters
    $^LForm feed (default "\f").
    $^AFormat Accumulator
    Status Reporting
    $?Child error. Status code of most recent system call or pipe.
    $!Operating System Error. (What just went 'bang'?)
    %!Error number hash
    $^EExtended Operating System Error (Extra error explanation).
    $@Eval error.
    ${^CHILD_ERROR_NATIVE}Native status returned by the last pipe close, backtick (`` ) command, successful call to wait() or waitpid(), or from the system() operator.
    ID's and Process Information
    $$Process ID
    $<Real user id of process.
    $>Effective user id of process.
    $(Real group id of process.
    $)Effective group id of process.
    $0Program name.
    $^OOperating System name.
    Perl Status Info
    $]Old: Version and patch number of perl interpreter. Deprecated.
    $^CCurrent value of flag associated with -c switch.
    $^DCurrent value of debugging flags
    $^FMaximum system file descriptor.
    $^IValue of the -i (inplace edit) switch.
    $^MEmergency Memory pool.
    $^PInternal variable for debugging support.
    $^RLast regexp (?{code}) result.
    $^SExceptions being caught. (eval)
    $^TBase time of program start.
    $^VPerl version.
    $^WStatus of -w switch
    ${^WARNING_BITS}Current set of warning checks enabled by use warnings;
    $^XPerl executable name.
    ${^GLOBAL_PHASE}Current phase of the Perl interpreter.
    $^HInternal use only: Hook into Lexical Scoping.
    %^HInternaluse only: Useful to implement scoped pragmas.
    ${^TAINT}Taint mode read-only flag.
    ${^WIN32_SLOPPY_STAT}If true on Windows stat() won't try to open the file.
    Command Line Args
    ARGVFilehandle iterates over files from command line (see also<>).
    $ARGVName of current file when reading <>
    @ARGVList of command line args.
    ARGVOUTOutput filehandle for -i switch
    Miscellaneous
    @FAutosplit (-a mode) recipient.
    @INCList of library paths.
    %INCKeys are filenames, values are paths to modules included via use, require, or do.
    %ENVHash containing current environment variables
    %SIGSignal handlers.
    $[Array and substr first element (Deprecated!).
    ================================================

    Uncommon* but Useful Perl Command Line Options for One-liners:

    Options covered herein therefor and whencebefore: -e, -p, -n,-l, -0,-a, -F, -M

    1. First up: -e (execute)

    perl -e '$date=localtime(time); print $date;'


    2. Next up: -l (line endings)

    perl -e '$date=localtime(time); print $date,"\n";'


    3. Next up: -n (looping)

    perl -l -n -e 'print $1 if /(\w+ear)/' some.txt


    4. Next up: -p (looping plus)

    perl -l -p -e 's/Microsoft/Micro\$\$\$oft/g' some.txt


    5. Next up: -a (split)

    perl -l -a -n -e 'print $F[5]' some.txt


    6. Next up: -0 (record separator)


    7. Finally: -M (& -m) (modules)

    -M like use Module; -m is like use Module();
    --------------------------

    1. confirm new Perl 5.8.0 is user Perl


    >>#perl -e 'print "$]\n";'----------->output:5.008008


    >>POD stands for Plain Old Documentation.
    $ perldoc perlpod

    >>=head1 .. =head4 commands (They are called command paragraphs officially. 
    eg:
    =head1 NAME
    
    My::Module - An example module

    No comments:

    Post a Comment