Perl – Practical Extraction and Report Language is a free high-level, interpreted, dynamic programming language written by Larry Wall in the year 1987.Perl is very good for shell scripting and regualar expression.If you use GNU/Linux is default installed, on windows you have to install ActivePerl.The languages includes Perl 5 and 6, I use primary Perl 5(Perl 5 is also continue developing).The symbol of the Perl language is the Camel symbol.
Variable
$ for Scalar,@ for Array and % for Hashes, as example:
my $name = "test"; my @name = ("test1","test2"); my %name = ("key1" => "test1","key2" => "test2");
In Perl all variables are Scalars, you could store numbers and strings in the same value without convert.If you want to add a Scalar to another you have to concate two strings with “.”, but if you want to add two number you should use “+”.To access an element from the array you could use “$name[0]”, it starts from 0 to the last element, you get the last element with “$#name”.For manipulating a Perl Array look at this Post.And you could choose in a big list of default variables.
Quoting
Be careful with quoting, the double quotes could interpolate other Scalars.
my $a = "1"; my $name1 = "$a"; my $name2 = '$a';
The name1 is “1” and name2 is “$a”.
an simple “Hello World!” example:
print "Hello World!\n";
Comparison
To compare the Scalars you could use them from this table:
compare type | number | string |
---|---|---|
equal | == | eq |
not equal | != | ne |
less than | < | lt |
greater than | > | gt |
less or equal | <= | le |
greater or equal | >= | ge |
loops
In Perl are more than one way to make a loop:
for(1..10){...} for(my $i=1;$i<=10;$i++){..}
the first one is faster and faster to write, but the second has more possibility’s to change.
Do-While loop:
do { ... }while(1);
While loop:
while(1) { ... }
Regex
Regular Expressions are very good implemented by Perl:
$x =~ s/a/b/og; if($x =~ /b/){ ... }
Optimizing
Perl is an interpreted language and if you need more performance you could use Inline code like C or you could take a look at my Benchmarks or at write fast code in Perl.
If you want to see some examples and solution from me see into my Category – Perl or if you want to see some special Tricks in Perl.
This article is truly a nice one it assists new web
people, who are wishing in favor of blogging.
Fastidious respond in return of this difficulty with firm arguments and describing all about that.