![]() |
|
Introduction to Perl - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Coding (https://sinister.ly/Forum-Coding--71) +--- Thread: Introduction to Perl (/Thread-Introduction-to-Perl) |
Introduction to Perl - noize - 07-06-2013 Introduction to Perl Basic programmin knowledge is required as some concepts (e.g. functions, variables) are given as known. Hello, world! Perl is a programming language developed by Larry Wall and first appeared in 1987. It is mostly inspired to AWK and sed. We'll start off with a simple Hello, world! example in Perl: Code: print "Hello, world!";
# in Perl, print works fine like this:
# print "this"
# or even like this:
# print("even this")
# though, it's probably preferable, and commonly used, to use print with no brackets
# P.S: "#" is a comment definerThe above code would display the line "Hello, world!". Perl, differently from many other languages does not add any line feed with the print function. Example Hello, world! in Perl and other programming languages: Perl Code: print "Hello, world!";Output: Code: Hello, world!PHP Code: echo "Hello, world!";Output: Code: Hello, world!
[newline] // MyBB was trimming this line, but this should be blankPython Code: print "Hello, world!"Output: Code: Hello, world!
[newline] # MyBB was trimming this line, but this should be blankLua Code: print("Hello, world!");Output: Code: Hello, world!
[newline] -- MyBB was trimming this line, but this should be blankCan you see the difference? Perl's print function does not add by default the line feed. This means that this script: Code: print "Hello, ";
print "world!";would still output "Hello, world!". To get this output: Code: Hello,
world!you would need to manually add a newline escaped sequence ("\n") in the code: Code: print "Hello,\n";
print "world!";This might seem worse for you lazy asses, but it makes everything easier when you, for instance, want to print a string and then print the output of another command (often, languages that add a newline with print have another function that allows to write with no forced line feed). Variables and string concatenation Perl has two types of variables: global and local. Global variables are defined by assigning any element to a variable name using the equal sign operator (=). Code: $myVar = "myString";
print $myVar;Local variables are defined using the my command. Code: my $myVar = "myString";
print $myVar;Local variables work for the current block only, while global variables are defined for the whole script. You can easily concatenate a string with a variable this way: Code: $var = "var";
print "var = $var";While enclosed in double quotes, variables are defined by the $ (dollar) sign and are replaced by their respective value, the same goes for escaped sequences (\n, \t, \r, et cetera). While they are enclosed in single quotes they are instead treated as regular strings. Code: print "Expect the...\n";
print 'newline (\n)';The above would output: Code: Expect the...
newline(\n)While this: Code: print "Expect the...\n";
print "newline(\n)";would output: Code: Expect the...
newline(
)If you instead wanted to print the value of a variable followed by another string, you couldn't do it this way: Code: $var = "String = ";
print "$varString";The above wouldn't output anything as the value of the $varString variable is null. You could either do it this way: Code: $var = "String = ";
print $var;
print "String";
# output: "String = String"or you could have used the string concatenation operator: Code: $var = "String = ";
print $var . "String";Commas are as well as dots valid concatenation operators. Functions Functions in Perl are defined by the sub (subroutine) command and are constituted by a command (sub), a function name (user-defined) and a block (the function's action). Here's an example: Code: sub myFunc {
print "Functions and ponies at www.hackcommunity.com.";
}The above is a void function not requiring any argument. It can be called like this: Code: myFunc()In Perl, you don't need to define functions in variables, like in many other languages, like Lua: Code: function sum(x,y)
return x + y
endPerl functions' arguments are similar to CLIs' arguments. A language that does not have in-built function support and that supplies to this lack by using pretty much the same kind of arguments is Batch: Code: :sum
set /a sum = %1 + %2
echo %sum%
goto :eof
call :sum 2 3Even though Perl has in-built function support, its functions work in a very similar way: Code: sub sum
{
return $_[0] + $_[1];
}
sub sub() { # notice the bracks
# we can define functions with no brackets, with brackets, even in variables:
sub subSub(x,y) {print $_[0];}
# it doesn't really matter, though, it's - for obvious reasons - preferable
# not to use variables, we don't really have a reason to do so
print "this function is never called";
}
print sum(1,2);The above script prints 3. You might have noticed that the first argument is not called $_[1], but $_[0] instead. In fact, the first argument in Perl is considered as the zero argument, the second as first and so on. Perl is not compiled before execution (though you might read "execution aborted due to compilation errors" errors while trying to run Perl scripts), but it is parsed once before being run and if there are relevant errors the interpreter will not even execute it (else it might execute it anyway and give some errors in the output, in less relevant cases (not actual errors), if warnings are enabled). For this reason we could also call a function before defining it. Code: print sq(3);
sub sq {
return $_[0] * $_[0];
}Arrays Arrays in Perl are defined by the @ character, though, to refer to a value in an array, we use the $ sign, just like for variables. Here's an example: Code: @array = ("value1","Don't forget spaghetti!","value3");
print "\n" , $array[0];
# print "value1"
print $array[2] , $array[0];
# print "value3value1"
print $array[1];
# print "Don't forget spaghetti!"
print "\n\nWhole array: @array\n\n";
# print "Whole array: value1 Don't forget spaghetti! value3"
print "Whole array again: " , @array , "\n";
# print "Whole array again: value1Don't forget spaghetti!value3"You'll have noticed that we refer to the first value using the index 0. That's just the same as we've seen in the functions chapter. When we call a value in an array by its index we use the $ sign, like for variables, while, when we call the whole array, we use the @ character. What you should notice is the difference between the fourth and the fifth output. In the fourth print call, we print @array enclosed in double quotes. This way, values get automatically separated with a whitespace character. When we call @array out of quotes, instead, the array is displayed with no separators. This is the whole output of the above file: Code: value1value3valueDon't forget spaghetti!
Whole array: value1 Don't forget spaghetti! value3
Whole array again: value1Don't forget spaghetti!value3If you're entering only values with no spaces, you might use the qw function. Code: @array = qw(Word Another one two blah);
# $array[1] == "Another"
# $array[4] == "blah"You can sort arrays using the sort function. Code: @goodGuys = qw(John James Jake Joe Hey Jude Jonny Jesus);
print sort(@goodGuys);The above script will print: Code: HeyJakeJamesJesusJoeJohnJonnyJudeAlthough, cases might cause problems while using the sort function. For example: Code: @goodGuys = qw(John James Jake Joe hey Jude Jonny Jesus);
print sort(@goodGuys);The above code, will not return Code: heyJakeJamesJesusJoeJohnJonnyJude, but this instead: Code: JakeJamesJesusJoeJohnJonnyJudeheyThe reason is that it bases upon the respective ASCII values order, and uppercase litters come first in the ASCII table. Editing arrays [table] [row] [cell] push() [/cell] [cell] Add an element to the end of an array [/cell] [/row] [row] [cell] pop() [/cell] [cell] Remove the last element of an array [/cell] [/row] [row] [cell] unshift() [/cell] [cell] Add an element to the beginning of an array [/cell] [/row] [row] [cell] shift() [/cell] [cell] Remove the first element of an array [/cell] [/row] [row] [cell] delete [/cell] [cell] Remove an element from an array by its index [/cell] [/row] [/table] Code: @hw = ("hello","world","!");
# hello world !
pop(@hw);
# hello world
push(@hw,"!");
# hello world !
shift(@hw);
# world !
unshift(@hw,"hello");
# hello world !
delete $hw[1];
# hello !We can get the number of elements in an array by either using the scalar function: Code: print scalar(@arr);or by just setting it to a variable's value: Code: $var = @arr;We could also use: Code: print @#arr + 1;In fact, $#array would return the index of the last element of an array, and, as Perl starts enumerating the elements from 0, the index of the last element will be one number less than the number of elements in the array. Though, this would fail if we manipulated the array, for instance by removing an element in the middle of the array. If an array does not exist yet, we can use the push or the unshift function to create an array with one value: Code: push(@newArray,"string");Arguments and the IF statement CLI arguments are stored in the ARGV array. Once again, the first is $ARGV[0], and not $ARGV[1], so, we have no way to get the name of the program using these arguments. To get the program name we can use the {0} variable instead. Code: if (($#ARGV < 0) || ($ARGV[0] eq '--help')) {
print "usage: just say your name";
} else {
print "hello, $ARGV[0].";
}When no additional arguments are specified, $#ARGV will return -1. In the above script, if either $#ARGV is less than 0 or $ARGV[0] (the first argument) is "--help" we print the usage, else we print "hello, $ARGV[0].", where $ARGV[0] is supposed to be the user's name. As you'll have already noticed, Perl's IF statement is pretty intuitive and similar to other languages (like AWK and PHP). It is constituted of a command (if), a condition and an action block. The condition must be enclosed in brackets. Though, subconditions like if ((condition1) || (condition2)) could also be left out of brackets (if (condition1 || condition2)). The double pipe (||) means or and so, if any of the two conditions are true, the action is executed. The and operator is instead &&. Code: $var = 2;
if ($var == 2 && 1 =~ 2) {
print "is";
}An equal sign followed by a tilde (=~) indicates disequality (the respective of what is in many languages != - you might have found =~ in Ruby before (not to be typoed for Lua's ~=)). If, else if: Code: $h = "hello";
if (1>=2) {
print "huh?";
} elsif ($h eq "hello") {
print "hello";
}For string comparison you need to use eq and not ==. The double equal is the numerical comparison operator. Numerical identity operators are ==, =~, <=, >=, < and >. We can check for string disequality using not. Code: if (not "hello" eq "Hello") {
print "This will be printed";
} else {
print "This won't be printed";
}Note that not must be enclosed in brackets. else is pretty self explanatory. In case the if condition is false, the else block is executed. if not can be replaced by unless. Code: $var = 1;
unless ($var == 2) {print '$var is ' . $var;}Although, unless is not the same as if not. Let me demonstrate it with an example where they differ: Code: if (not 1==1 && 1==2) {}
unless (1==1 && 1==2) {}An if condition equal to the latter unless condition would be: Code: if (not 1==1 && not 1==2) {}An unless condition equal to the earlier if condition would instead be: Code: unless (1==1 && not 1==2) {}Algebrical operators [table] [row] [cell] + [/cell] [cell] sum [/cell] [/row] [row] [cell] - [/cell] [cell] subtraction [/cell] [/row] [row] [cell] * [/cell] [cell] multiplication [/cell] [/row] [row] [cell] / [/cell] [cell] division [/cell] [/row] [row] [cell] % [/cell] [cell] modulo [/cell] [/row] [row] [cell] ** [/cell] [cell] power [/cell] [/row] [row] [cell] sqrt() [/cell] [cell] square root [/cell] [/row] [row] [cell] ++ [/cell] [cell] increment [/cell] [/row] [row] [cell] -- [/cell] [cell] decrease [/cell] [/row] [/table] We can execute algebrical operations mostly anywhere in Perl. We can directly assign their result to variables: Code: $x = 10 + 5;
# 15Print results of operations: Code: $y = 10;
print sqrt(4) - $y;
# 2 - 10 = -8Append results to arrays: Code: push(@arr,(10*(2**3))/4);
# (10 * 2^3) / 4 =
# = (10 * 8) / 4 =
# = 80 / 4 =
# = 20We can generate ranges of numbers using the range operator (..). Code: print 10..15;
# 101112131415And what if we wanted to print them separated by spaces? We put them in array first. Code: @nums = 1 .. 9 , 11 .. 19;
print "@arr";
# 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19The range operator works for all ASCII characters, here's an example script: Code: @alphabet = a .. z;
print scalar(@alphabet) . " litters for you: @alphabet" . ".";As we had seen earlier, we get the number of elements in an array using the scalar function. The output of the above script would be: Code: 26 litters for you: a b c d [...] w x y z."Perl supports C-like increase and decrease operators: Code: $x=1;
# x == 1
$x++;
# x == 2
$x--;
# x == 1Other than as standalone assigners, they can be called within other commands: Code: $x = 10;
print $x++;The above code will print 10 as, when the operator follows the variable name, we first print its value and then assign it to the new value. If we wanted instead to first assign it to a new value, we just add to put the operator before the variable name: Code: $x = 5;
print $x++;
# prints 5
print --$x;
# prints 5
print ++$x;
# prints 6
print $x--;
# prints 6
print $x;
# prints 5Let's take the code bit by bit. x is 5, we print x++ and we output 5 as long as the operator is following the x. Now x is 6, we print --x but we still get 5 'cause we first decrease the value of x and then print it. Now x is 5 again, we first increase the value of x and then print 6. Then print x and then decrease the value of x. Now x is 5 again. Loops & the goto statement Being Perl a strong-typing language, just like for the other similar structures (i.e. the procedure declaration (sub), or the more similar if statement), characteristical tokens like condition or action blocks' brackets are not substituteable. The for loop is pretty much like in most of the other programming languages like C, C++ or PHP. The syntax is: Code: for (startingDefinition;loopCondition;delta) {
# looped
}"startingDefinition" is a variable definition (e.g: $i=1). "loopCondition" is the condition for the loop to exist (e.g: $i < 10). "delta" is the variation of the variable's value (e.g: i++). An example loop: Code: for ($i=10;$i<=100;$i++) {
print $i . "\n";
}The while loop is constituted by a "while" statement, a condition expression and an action block. Code: while (true) {
print "of course\n";
}The above is an endless while loop. Perl's for loops can be emulated with a while statement using the continue statement. The continue statement in Perl is not to be confused with Python's continue statement. Python's continue statement ignores the rest (after "continue") of the loop computations and jumps to the next loop iteration, like a break of the current iteration only. The following example script will keep on printing "1". Code: while 1==1:
print(1)
continue # back to the start
print("this is not output")In Perl, the continue statement defines instead an action block to be executed at every loop iteration, no matter how the loop goes. Code: $i = 1;
while ($i == 1) {
print 1;
next;
print 3;
} continue {
print 2 . "\n";
}The last statement is actually the same as Python's continue statement. The output of the above code would be: Code: 12
12
12
12
12
...As you can see, the continue block is executed before the program goes to the next iteration. That's not the same for the last and the redo statements. Perl has three loop control statements: next, last and redo. last is the same as what is the break statement in many languages. last stops executing the loop at the current point, dropping any commands to execute before the loop may end, in the continue block and drops out of the loop as well. Code: while ($i == 1) {
print 1;
last;
print 3;
} continue {
print 2 . "\n";
}The above script would output "1" and then break. Code: 1redo works a bit like both last and next. It breaks the execution of the current iteration without executing the continue block (like last) and it goes back to the beginning of the loop's main block (like next) without re-evaluating the loop's condition. What this means is that even if the condition for the loop to exist is not respected anymore, the block will be reiterated anyway. The loop control statements can be used in any kind of loop. Code: for ($i = 1; $i < 2; $i++) {
$i++;
redo;
}The above will execute endlessly, as there is no condition for the redo statement to be executed. while supports the do while form as well: Code: do {
# what you wanna do
} while (stuff happens)Just like in PHP's while or in the for loop, Perl supports variable declarations in the while condition block. Code: while ($var = 1) {
# this can be more likely useful while handling arrays
}The until loop stays to while just like unless stays to if: it executes the block until the condition is false. Code: until (1==2) {
# endless loop
}The foreach loop can help iterating through the elements of an array without having to manually pick up each of them. Code: @arr = {'foo','bar'}
foreach (@arr) {
print "$_";
}The above script will output "foobar". Another use of foreach might be to iterate through the elements of an hash as well, but as we didn't see anything about Perl's hashes yet, we'll leave this out (I might add it later). Note: Perl's hashes are like associative arrays (i.e. tables). Even though the foreach loop was the last loop we'd find, we still have to talk about the goto statement. The goto statement might constitute actual loops, but it's not a loop procedural structure. The goto statement is just a coarse procedural jump. In my opinion, the goto statement should (or at least could) be removed from any language but Assembly, machine languages, strict "low level" system shell scripting languages (with "low level", here I don't actually mean low level languages, but literally sloppier languages) and, Visual Basic (the reason for this latter is that it's a mostly shoddy language, good for beginners and people wanting to experiment rough coding structures). All though, Perl has a goto statement, and so here I go to explain it: Code: LABEL:
# this is a label. in VB and some system shell scripting languages
# labels are defined by a colon followed by the label name
# in Perl, it is defined by the label name followed by a colon
if ($conditionToBeRespected) { # this is equal to
# if ($conditionToBeRespected == true) {
goto LABEL;
}Let's pretend the condition is always true: Code: $conditionToBeRespected = trueThis is in fact an endless loop. The program will run like this: Code: LABEL
IF TRUE THEN GOTO LABELWill soon update the thread with the following chapters: // FILES HANDLING Introduction to Perl - noize - 07-06-2013 Introduction to Perl Basic programmin knowledge is required as some concepts (e.g. functions, variables) are given as known. Hello, world! Perl is a programming language developed by Larry Wall and first appeared in 1987. It is mostly inspired to AWK and sed. We'll start off with a simple Hello, world! example in Perl: Code: print "Hello, world!";
# in Perl, print works fine like this:
# print "this"
# or even like this:
# print("even this")
# though, it's probably preferable, and commonly used, to use print with no brackets
# P.S: "#" is a comment definerThe above code would display the line "Hello, world!". Perl, differently from many other languages does not add any line feed with the print function. Example Hello, world! in Perl and other programming languages: Perl Code: print "Hello, world!";Output: Code: Hello, world!PHP Code: echo "Hello, world!";Output: Code: Hello, world!
[newline] // MyBB was trimming this line, but this should be blankPython Code: print "Hello, world!"Output: Code: Hello, world!
[newline] # MyBB was trimming this line, but this should be blankLua Code: print("Hello, world!");Output: Code: Hello, world!
[newline] -- MyBB was trimming this line, but this should be blankCan you see the difference? Perl's print function does not add by default the line feed. This means that this script: Code: print "Hello, ";
print "world!";would still output "Hello, world!". To get this output: Code: Hello,
world!you would need to manually add a newline escaped sequence ("\n") in the code: Code: print "Hello,\n";
print "world!";This might seem worse for you lazy asses, but it makes everything easier when you, for instance, want to print a string and then print the output of another command (often, languages that add a newline with print have another function that allows to write with no forced line feed). Variables and string concatenation Perl has two types of variables: global and local. Global variables are defined by assigning any element to a variable name using the equal sign operator (=). Code: $myVar = "myString";
print $myVar;Local variables are defined using the my command. Code: my $myVar = "myString";
print $myVar;Local variables work for the current block only, while global variables are defined for the whole script. You can easily concatenate a string with a variable this way: Code: $var = "var";
print "var = $var";While enclosed in double quotes, variables are defined by the $ (dollar) sign and are replaced by their respective value, the same goes for escaped sequences (\n, \t, \r, et cetera). While they are enclosed in single quotes they are instead treated as regular strings. Code: print "Expect the...\n";
print 'newline (\n)';The above would output: Code: Expect the...
newline(\n)While this: Code: print "Expect the...\n";
print "newline(\n)";would output: Code: Expect the...
newline(
)If you instead wanted to print the value of a variable followed by another string, you couldn't do it this way: Code: $var = "String = ";
print "$varString";The above wouldn't output anything as the value of the $varString variable is null. You could either do it this way: Code: $var = "String = ";
print $var;
print "String";
# output: "String = String"or you could have used the string concatenation operator: Code: $var = "String = ";
print $var . "String";Commas are as well as dots valid concatenation operators. Functions Functions in Perl are defined by the sub (subroutine) command and are constituted by a command (sub), a function name (user-defined) and a block (the function's action). Here's an example: Code: sub myFunc {
print "Functions and ponies at www.hackcommunity.com.";
}The above is a void function not requiring any argument. It can be called like this: Code: myFunc()In Perl, you don't need to define functions in variables, like in many other languages, like Lua: Code: function sum(x,y)
return x + y
endPerl functions' arguments are similar to CLIs' arguments. A language that does not have in-built function support and that supplies to this lack by using pretty much the same kind of arguments is Batch: Code: :sum
set /a sum = %1 + %2
echo %sum%
goto :eof
call :sum 2 3Even though Perl has in-built function support, its functions work in a very similar way: Code: sub sum
{
return $_[0] + $_[1];
}
sub sub() { # notice the bracks
# we can define functions with no brackets, with brackets, even in variables:
sub subSub(x,y) {print $_[0];}
# it doesn't really matter, though, it's - for obvious reasons - preferable
# not to use variables, we don't really have a reason to do so
print "this function is never called";
}
print sum(1,2);The above script prints 3. You might have noticed that the first argument is not called $_[1], but $_[0] instead. In fact, the first argument in Perl is considered as the zero argument, the second as first and so on. Perl is not compiled before execution (though you might read "execution aborted due to compilation errors" errors while trying to run Perl scripts), but it is parsed once before being run and if there are relevant errors the interpreter will not even execute it (else it might execute it anyway and give some errors in the output, in less relevant cases (not actual errors), if warnings are enabled). For this reason we could also call a function before defining it. Code: print sq(3);
sub sq {
return $_[0] * $_[0];
}Arrays Arrays in Perl are defined by the @ character, though, to refer to a value in an array, we use the $ sign, just like for variables. Here's an example: Code: @array = ("value1","Don't forget spaghetti!","value3");
print "\n" , $array[0];
# print "value1"
print $array[2] , $array[0];
# print "value3value1"
print $array[1];
# print "Don't forget spaghetti!"
print "\n\nWhole array: @array\n\n";
# print "Whole array: value1 Don't forget spaghetti! value3"
print "Whole array again: " , @array , "\n";
# print "Whole array again: value1Don't forget spaghetti!value3"You'll have noticed that we refer to the first value using the index 0. That's just the same as we've seen in the functions chapter. When we call a value in an array by its index we use the $ sign, like for variables, while, when we call the whole array, we use the @ character. What you should notice is the difference between the fourth and the fifth output. In the fourth print call, we print @array enclosed in double quotes. This way, values get automatically separated with a whitespace character. When we call @array out of quotes, instead, the array is displayed with no separators. This is the whole output of the above file: Code: value1value3valueDon't forget spaghetti!
Whole array: value1 Don't forget spaghetti! value3
Whole array again: value1Don't forget spaghetti!value3If you're entering only values with no spaces, you might use the qw function. Code: @array = qw(Word Another one two blah);
# $array[1] == "Another"
# $array[4] == "blah"You can sort arrays using the sort function. Code: @goodGuys = qw(John James Jake Joe Hey Jude Jonny Jesus);
print sort(@goodGuys);The above script will print: Code: HeyJakeJamesJesusJoeJohnJonnyJudeAlthough, cases might cause problems while using the sort function. For example: Code: @goodGuys = qw(John James Jake Joe hey Jude Jonny Jesus);
print sort(@goodGuys);The above code, will not return Code: heyJakeJamesJesusJoeJohnJonnyJude, but this instead: Code: JakeJamesJesusJoeJohnJonnyJudeheyThe reason is that it bases upon the respective ASCII values order, and uppercase litters come first in the ASCII table. Editing arrays [table] [row] [cell] push() [/cell] [cell] Add an element to the end of an array [/cell] [/row] [row] [cell] pop() [/cell] [cell] Remove the last element of an array [/cell] [/row] [row] [cell] unshift() [/cell] [cell] Add an element to the beginning of an array [/cell] [/row] [row] [cell] shift() [/cell] [cell] Remove the first element of an array [/cell] [/row] [row] [cell] delete [/cell] [cell] Remove an element from an array by its index [/cell] [/row] [/table] Code: @hw = ("hello","world","!");
# hello world !
pop(@hw);
# hello world
push(@hw,"!");
# hello world !
shift(@hw);
# world !
unshift(@hw,"hello");
# hello world !
delete $hw[1];
# hello !We can get the number of elements in an array by either using the scalar function: Code: print scalar(@arr);or by just setting it to a variable's value: Code: $var = @arr;We could also use: Code: print @#arr + 1;In fact, $#array would return the index of the last element of an array, and, as Perl starts enumerating the elements from 0, the index of the last element will be one number less than the number of elements in the array. Though, this would fail if we manipulated the array, for instance by removing an element in the middle of the array. If an array does not exist yet, we can use the push or the unshift function to create an array with one value: Code: push(@newArray,"string");Arguments and the IF statement CLI arguments are stored in the ARGV array. Once again, the first is $ARGV[0], and not $ARGV[1], so, we have no way to get the name of the program using these arguments. To get the program name we can use the {0} variable instead. Code: if (($#ARGV < 0) || ($ARGV[0] eq '--help')) {
print "usage: just say your name";
} else {
print "hello, $ARGV[0].";
}When no additional arguments are specified, $#ARGV will return -1. In the above script, if either $#ARGV is less than 0 or $ARGV[0] (the first argument) is "--help" we print the usage, else we print "hello, $ARGV[0].", where $ARGV[0] is supposed to be the user's name. As you'll have already noticed, Perl's IF statement is pretty intuitive and similar to other languages (like AWK and PHP). It is constituted of a command (if), a condition and an action block. The condition must be enclosed in brackets. Though, subconditions like if ((condition1) || (condition2)) could also be left out of brackets (if (condition1 || condition2)). The double pipe (||) means or and so, if any of the two conditions are true, the action is executed. The and operator is instead &&. Code: $var = 2;
if ($var == 2 && 1 =~ 2) {
print "is";
}An equal sign followed by a tilde (=~) indicates disequality (the respective of what is in many languages != - you might have found =~ in Ruby before (not to be typoed for Lua's ~=)). If, else if: Code: $h = "hello";
if (1>=2) {
print "huh?";
} elsif ($h eq "hello") {
print "hello";
}For string comparison you need to use eq and not ==. The double equal is the numerical comparison operator. Numerical identity operators are ==, =~, <=, >=, < and >. We can check for string disequality using not. Code: if (not "hello" eq "Hello") {
print "This will be printed";
} else {
print "This won't be printed";
}Note that not must be enclosed in brackets. else is pretty self explanatory. In case the if condition is false, the else block is executed. if not can be replaced by unless. Code: $var = 1;
unless ($var == 2) {print '$var is ' . $var;}Although, unless is not the same as if not. Let me demonstrate it with an example where they differ: Code: if (not 1==1 && 1==2) {}
unless (1==1 && 1==2) {}An if condition equal to the latter unless condition would be: Code: if (not 1==1 && not 1==2) {}An unless condition equal to the earlier if condition would instead be: Code: unless (1==1 && not 1==2) {}Algebrical operators [table] [row] [cell] + [/cell] [cell] sum [/cell] [/row] [row] [cell] - [/cell] [cell] subtraction [/cell] [/row] [row] [cell] * [/cell] [cell] multiplication [/cell] [/row] [row] [cell] / [/cell] [cell] division [/cell] [/row] [row] [cell] % [/cell] [cell] modulo [/cell] [/row] [row] [cell] ** [/cell] [cell] power [/cell] [/row] [row] [cell] sqrt() [/cell] [cell] square root [/cell] [/row] [row] [cell] ++ [/cell] [cell] increment [/cell] [/row] [row] [cell] -- [/cell] [cell] decrease [/cell] [/row] [/table] We can execute algebrical operations mostly anywhere in Perl. We can directly assign their result to variables: Code: $x = 10 + 5;
# 15Print results of operations: Code: $y = 10;
print sqrt(4) - $y;
# 2 - 10 = -8Append results to arrays: Code: push(@arr,(10*(2**3))/4);
# (10 * 2^3) / 4 =
# = (10 * 8) / 4 =
# = 80 / 4 =
# = 20We can generate ranges of numbers using the range operator (..). Code: print 10..15;
# 101112131415And what if we wanted to print them separated by spaces? We put them in array first. Code: @nums = 1 .. 9 , 11 .. 19;
print "@arr";
# 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19The range operator works for all ASCII characters, here's an example script: Code: @alphabet = a .. z;
print scalar(@alphabet) . " litters for you: @alphabet" . ".";As we had seen earlier, we get the number of elements in an array using the scalar function. The output of the above script would be: Code: 26 litters for you: a b c d [...] w x y z."Perl supports C-like increase and decrease operators: Code: $x=1;
# x == 1
$x++;
# x == 2
$x--;
# x == 1Other than as standalone assigners, they can be called within other commands: Code: $x = 10;
print $x++;The above code will print 10 as, when the operator follows the variable name, we first print its value and then assign it to the new value. If we wanted instead to first assign it to a new value, we just add to put the operator before the variable name: Code: $x = 5;
print $x++;
# prints 5
print --$x;
# prints 5
print ++$x;
# prints 6
print $x--;
# prints 6
print $x;
# prints 5Let's take the code bit by bit. x is 5, we print x++ and we output 5 as long as the operator is following the x. Now x is 6, we print --x but we still get 5 'cause we first decrease the value of x and then print it. Now x is 5 again, we first increase the value of x and then print 6. Then print x and then decrease the value of x. Now x is 5 again. Loops & the goto statement Being Perl a strong-typing language, just like for the other similar structures (i.e. the procedure declaration (sub), or the more similar if statement), characteristical tokens like condition or action blocks' brackets are not substituteable. The for loop is pretty much like in most of the other programming languages like C, C++ or PHP. The syntax is: Code: for (startingDefinition;loopCondition;delta) {
# looped
}"startingDefinition" is a variable definition (e.g: $i=1). "loopCondition" is the condition for the loop to exist (e.g: $i < 10). "delta" is the variation of the variable's value (e.g: i++). An example loop: Code: for ($i=10;$i<=100;$i++) {
print $i . "\n";
}The while loop is constituted by a "while" statement, a condition expression and an action block. Code: while (true) {
print "of course\n";
}The above is an endless while loop. Perl's for loops can be emulated with a while statement using the continue statement. The continue statement in Perl is not to be confused with Python's continue statement. Python's continue statement ignores the rest (after "continue") of the loop computations and jumps to the next loop iteration, like a break of the current iteration only. The following example script will keep on printing "1". Code: while 1==1:
print(1)
continue # back to the start
print("this is not output")In Perl, the continue statement defines instead an action block to be executed at every loop iteration, no matter how the loop goes. Code: $i = 1;
while ($i == 1) {
print 1;
next;
print 3;
} continue {
print 2 . "\n";
}The last statement is actually the same as Python's continue statement. The output of the above code would be: Code: 12
12
12
12
12
...As you can see, the continue block is executed before the program goes to the next iteration. That's not the same for the last and the redo statements. Perl has three loop control statements: next, last and redo. last is the same as what is the break statement in many languages. last stops executing the loop at the current point, dropping any commands to execute before the loop may end, in the continue block and drops out of the loop as well. Code: while ($i == 1) {
print 1;
last;
print 3;
} continue {
print 2 . "\n";
}The above script would output "1" and then break. Code: 1redo works a bit like both last and next. It breaks the execution of the current iteration without executing the continue block (like last) and it goes back to the beginning of the loop's main block (like next) without re-evaluating the loop's condition. What this means is that even if the condition for the loop to exist is not respected anymore, the block will be reiterated anyway. The loop control statements can be used in any kind of loop. Code: for ($i = 1; $i < 2; $i++) {
$i++;
redo;
}The above will execute endlessly, as there is no condition for the redo statement to be executed. while supports the do while form as well: Code: do {
# what you wanna do
} while (stuff happens)Just like in PHP's while or in the for loop, Perl supports variable declarations in the while condition block. Code: while ($var = 1) {
# this can be more likely useful while handling arrays
}The until loop stays to while just like unless stays to if: it executes the block until the condition is false. Code: until (1==2) {
# endless loop
}The foreach loop can help iterating through the elements of an array without having to manually pick up each of them. Code: @arr = {'foo','bar'}
foreach (@arr) {
print "$_";
}The above script will output "foobar". Another use of foreach might be to iterate through the elements of an hash as well, but as we didn't see anything about Perl's hashes yet, we'll leave this out (I might add it later). Note: Perl's hashes are like associative arrays (i.e. tables). Even though the foreach loop was the last loop we'd find, we still have to talk about the goto statement. The goto statement might constitute actual loops, but it's not a loop procedural structure. The goto statement is just a coarse procedural jump. In my opinion, the goto statement should (or at least could) be removed from any language but Assembly, machine languages, strict "low level" system shell scripting languages (with "low level", here I don't actually mean low level languages, but literally sloppier languages) and, Visual Basic (the reason for this latter is that it's a mostly shoddy language, good for beginners and people wanting to experiment rough coding structures). All though, Perl has a goto statement, and so here I go to explain it: Code: LABEL:
# this is a label. in VB and some system shell scripting languages
# labels are defined by a colon followed by the label name
# in Perl, it is defined by the label name followed by a colon
if ($conditionToBeRespected) { # this is equal to
# if ($conditionToBeRespected == true) {
goto LABEL;
}Let's pretend the condition is always true: Code: $conditionToBeRespected = trueThis is in fact an endless loop. The program will run like this: Code: LABEL
IF TRUE THEN GOTO LABELWill soon update the thread with the following chapters: // FILES HANDLING Introduction to Perl - noize - 07-06-2013 Introduction to Perl Basic programmin knowledge is required as some concepts (e.g. functions, variables) are given as known. Hello, world! Perl is a programming language developed by Larry Wall and first appeared in 1987. It is mostly inspired to AWK and sed. We'll start off with a simple Hello, world! example in Perl: Code: print "Hello, world!";
# in Perl, print works fine like this:
# print "this"
# or even like this:
# print("even this")
# though, it's probably preferable, and commonly used, to use print with no brackets
# P.S: "#" is a comment definerThe above code would display the line "Hello, world!". Perl, differently from many other languages does not add any line feed with the print function. Example Hello, world! in Perl and other programming languages: Perl Code: print "Hello, world!";Output: Code: Hello, world!PHP Code: echo "Hello, world!";Output: Code: Hello, world!
[newline] // MyBB was trimming this line, but this should be blankPython Code: print "Hello, world!"Output: Code: Hello, world!
[newline] # MyBB was trimming this line, but this should be blankLua Code: print("Hello, world!");Output: Code: Hello, world!
[newline] -- MyBB was trimming this line, but this should be blankCan you see the difference? Perl's print function does not add by default the line feed. This means that this script: Code: print "Hello, ";
print "world!";would still output "Hello, world!". To get this output: Code: Hello,
world!you would need to manually add a newline escaped sequence ("\n") in the code: Code: print "Hello,\n";
print "world!";This might seem worse for you lazy asses, but it makes everything easier when you, for instance, want to print a string and then print the output of another command (often, languages that add a newline with print have another function that allows to write with no forced line feed). Variables and string concatenation Perl has two types of variables: global and local. Global variables are defined by assigning any element to a variable name using the equal sign operator (=). Code: $myVar = "myString";
print $myVar;Local variables are defined using the my command. Code: my $myVar = "myString";
print $myVar;Local variables work for the current block only, while global variables are defined for the whole script. You can easily concatenate a string with a variable this way: Code: $var = "var";
print "var = $var";While enclosed in double quotes, variables are defined by the $ (dollar) sign and are replaced by their respective value, the same goes for escaped sequences (\n, \t, \r, et cetera). While they are enclosed in single quotes they are instead treated as regular strings. Code: print "Expect the...\n";
print 'newline (\n)';The above would output: Code: Expect the...
newline(\n)While this: Code: print "Expect the...\n";
print "newline(\n)";would output: Code: Expect the...
newline(
)If you instead wanted to print the value of a variable followed by another string, you couldn't do it this way: Code: $var = "String = ";
print "$varString";The above wouldn't output anything as the value of the $varString variable is null. You could either do it this way: Code: $var = "String = ";
print $var;
print "String";
# output: "String = String"or you could have used the string concatenation operator: Code: $var = "String = ";
print $var . "String";Commas are as well as dots valid concatenation operators. Functions Functions in Perl are defined by the sub (subroutine) command and are constituted by a command (sub), a function name (user-defined) and a block (the function's action). Here's an example: Code: sub myFunc {
print "Functions and ponies at www.hackcommunity.com.";
}The above is a void function not requiring any argument. It can be called like this: Code: myFunc()In Perl, you don't need to define functions in variables, like in many other languages, like Lua: Code: function sum(x,y)
return x + y
endPerl functions' arguments are similar to CLIs' arguments. A language that does not have in-built function support and that supplies to this lack by using pretty much the same kind of arguments is Batch: Code: :sum
set /a sum = %1 + %2
echo %sum%
goto :eof
call :sum 2 3Even though Perl has in-built function support, its functions work in a very similar way: Code: sub sum
{
return $_[0] + $_[1];
}
sub sub() { # notice the bracks
# we can define functions with no brackets, with brackets, even in variables:
sub subSub(x,y) {print $_[0];}
# it doesn't really matter, though, it's - for obvious reasons - preferable
# not to use variables, we don't really have a reason to do so
print "this function is never called";
}
print sum(1,2);The above script prints 3. You might have noticed that the first argument is not called $_[1], but $_[0] instead. In fact, the first argument in Perl is considered as the zero argument, the second as first and so on. Perl is not compiled before execution (though you might read "execution aborted due to compilation errors" errors while trying to run Perl scripts), but it is parsed once before being run and if there are relevant errors the interpreter will not even execute it (else it might execute it anyway and give some errors in the output, in less relevant cases (not actual errors), if warnings are enabled). For this reason we could also call a function before defining it. Code: print sq(3);
sub sq {
return $_[0] * $_[0];
}Arrays Arrays in Perl are defined by the @ character, though, to refer to a value in an array, we use the $ sign, just like for variables. Here's an example: Code: @array = ("value1","Don't forget spaghetti!","value3");
print "\n" , $array[0];
# print "value1"
print $array[2] , $array[0];
# print "value3value1"
print $array[1];
# print "Don't forget spaghetti!"
print "\n\nWhole array: @array\n\n";
# print "Whole array: value1 Don't forget spaghetti! value3"
print "Whole array again: " , @array , "\n";
# print "Whole array again: value1Don't forget spaghetti!value3"You'll have noticed that we refer to the first value using the index 0. That's just the same as we've seen in the functions chapter. When we call a value in an array by its index we use the $ sign, like for variables, while, when we call the whole array, we use the @ character. What you should notice is the difference between the fourth and the fifth output. In the fourth print call, we print @array enclosed in double quotes. This way, values get automatically separated with a whitespace character. When we call @array out of quotes, instead, the array is displayed with no separators. This is the whole output of the above file: Code: value1value3valueDon't forget spaghetti!
Whole array: value1 Don't forget spaghetti! value3
Whole array again: value1Don't forget spaghetti!value3If you're entering only values with no spaces, you might use the qw function. Code: @array = qw(Word Another one two blah);
# $array[1] == "Another"
# $array[4] == "blah"You can sort arrays using the sort function. Code: @goodGuys = qw(John James Jake Joe Hey Jude Jonny Jesus);
print sort(@goodGuys);The above script will print: Code: HeyJakeJamesJesusJoeJohnJonnyJudeAlthough, cases might cause problems while using the sort function. For example: Code: @goodGuys = qw(John James Jake Joe hey Jude Jonny Jesus);
print sort(@goodGuys);The above code, will not return Code: heyJakeJamesJesusJoeJohnJonnyJude, but this instead: Code: JakeJamesJesusJoeJohnJonnyJudeheyThe reason is that it bases upon the respective ASCII values order, and uppercase litters come first in the ASCII table. Editing arrays [table] [row] [cell] push() [/cell] [cell] Add an element to the end of an array [/cell] [/row] [row] [cell] pop() [/cell] [cell] Remove the last element of an array [/cell] [/row] [row] [cell] unshift() [/cell] [cell] Add an element to the beginning of an array [/cell] [/row] [row] [cell] shift() [/cell] [cell] Remove the first element of an array [/cell] [/row] [row] [cell] delete [/cell] [cell] Remove an element from an array by its index [/cell] [/row] [/table] Code: @hw = ("hello","world","!");
# hello world !
pop(@hw);
# hello world
push(@hw,"!");
# hello world !
shift(@hw);
# world !
unshift(@hw,"hello");
# hello world !
delete $hw[1];
# hello !We can get the number of elements in an array by either using the scalar function: Code: print scalar(@arr);or by just setting it to a variable's value: Code: $var = @arr;We could also use: Code: print @#arr + 1;In fact, $#array would return the index of the last element of an array, and, as Perl starts enumerating the elements from 0, the index of the last element will be one number less than the number of elements in the array. Though, this would fail if we manipulated the array, for instance by removing an element in the middle of the array. If an array does not exist yet, we can use the push or the unshift function to create an array with one value: Code: push(@newArray,"string");Arguments and the IF statement CLI arguments are stored in the ARGV array. Once again, the first is $ARGV[0], and not $ARGV[1], so, we have no way to get the name of the program using these arguments. To get the program name we can use the {0} variable instead. Code: if (($#ARGV < 0) || ($ARGV[0] eq '--help')) {
print "usage: just say your name";
} else {
print "hello, $ARGV[0].";
}When no additional arguments are specified, $#ARGV will return -1. In the above script, if either $#ARGV is less than 0 or $ARGV[0] (the first argument) is "--help" we print the usage, else we print "hello, $ARGV[0].", where $ARGV[0] is supposed to be the user's name. As you'll have already noticed, Perl's IF statement is pretty intuitive and similar to other languages (like AWK and PHP). It is constituted of a command (if), a condition and an action block. The condition must be enclosed in brackets. Though, subconditions like if ((condition1) || (condition2)) could also be left out of brackets (if (condition1 || condition2)). The double pipe (||) means or and so, if any of the two conditions are true, the action is executed. The and operator is instead &&. Code: $var = 2;
if ($var == 2 && 1 =~ 2) {
print "is";
}An equal sign followed by a tilde (=~) indicates disequality (the respective of what is in many languages != - you might have found =~ in Ruby before (not to be typoed for Lua's ~=)). If, else if: Code: $h = "hello";
if (1>=2) {
print "huh?";
} elsif ($h eq "hello") {
print "hello";
}For string comparison you need to use eq and not ==. The double equal is the numerical comparison operator. Numerical identity operators are ==, =~, <=, >=, < and >. We can check for string disequality using not. Code: if (not "hello" eq "Hello") {
print "This will be printed";
} else {
print "This won't be printed";
}Note that not must be enclosed in brackets. else is pretty self explanatory. In case the if condition is false, the else block is executed. if not can be replaced by unless. Code: $var = 1;
unless ($var == 2) {print '$var is ' . $var;}Although, unless is not the same as if not. Let me demonstrate it with an example where they differ: Code: if (not 1==1 && 1==2) {}
unless (1==1 && 1==2) {}An if condition equal to the latter unless condition would be: Code: if (not 1==1 && not 1==2) {}An unless condition equal to the earlier if condition would instead be: Code: unless (1==1 && not 1==2) {}Algebrical operators [table] [row] [cell] + [/cell] [cell] sum [/cell] [/row] [row] [cell] - [/cell] [cell] subtraction [/cell] [/row] [row] [cell] * [/cell] [cell] multiplication [/cell] [/row] [row] [cell] / [/cell] [cell] division [/cell] [/row] [row] [cell] % [/cell] [cell] modulo [/cell] [/row] [row] [cell] ** [/cell] [cell] power [/cell] [/row] [row] [cell] sqrt() [/cell] [cell] square root [/cell] [/row] [row] [cell] ++ [/cell] [cell] increment [/cell] [/row] [row] [cell] -- [/cell] [cell] decrease [/cell] [/row] [/table] We can execute algebrical operations mostly anywhere in Perl. We can directly assign their result to variables: Code: $x = 10 + 5;
# 15Print results of operations: Code: $y = 10;
print sqrt(4) - $y;
# 2 - 10 = -8Append results to arrays: Code: push(@arr,(10*(2**3))/4);
# (10 * 2^3) / 4 =
# = (10 * 8) / 4 =
# = 80 / 4 =
# = 20We can generate ranges of numbers using the range operator (..). Code: print 10..15;
# 101112131415And what if we wanted to print them separated by spaces? We put them in array first. Code: @nums = 1 .. 9 , 11 .. 19;
print "@arr";
# 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19The range operator works for all ASCII characters, here's an example script: Code: @alphabet = a .. z;
print scalar(@alphabet) . " litters for you: @alphabet" . ".";As we had seen earlier, we get the number of elements in an array using the scalar function. The output of the above script would be: Code: 26 litters for you: a b c d [...] w x y z."Perl supports C-like increase and decrease operators: Code: $x=1;
# x == 1
$x++;
# x == 2
$x--;
# x == 1Other than as standalone assigners, they can be called within other commands: Code: $x = 10;
print $x++;The above code will print 10 as, when the operator follows the variable name, we first print its value and then assign it to the new value. If we wanted instead to first assign it to a new value, we just add to put the operator before the variable name: Code: $x = 5;
print $x++;
# prints 5
print --$x;
# prints 5
print ++$x;
# prints 6
print $x--;
# prints 6
print $x;
# prints 5Let's take the code bit by bit. x is 5, we print x++ and we output 5 as long as the operator is following the x. Now x is 6, we print --x but we still get 5 'cause we first decrease the value of x and then print it. Now x is 5 again, we first increase the value of x and then print 6. Then print x and then decrease the value of x. Now x is 5 again. Loops & the goto statement Being Perl a strong-typing language, just like for the other similar structures (i.e. the procedure declaration (sub), or the more similar if statement), characteristical tokens like condition or action blocks' brackets are not substituteable. The for loop is pretty much like in most of the other programming languages like C, C++ or PHP. The syntax is: Code: for (startingDefinition;loopCondition;delta) {
# looped
}"startingDefinition" is a variable definition (e.g: $i=1). "loopCondition" is the condition for the loop to exist (e.g: $i < 10). "delta" is the variation of the variable's value (e.g: i++). An example loop: Code: for ($i=10;$i<=100;$i++) {
print $i . "\n";
}The while loop is constituted by a "while" statement, a condition expression and an action block. Code: while (true) {
print "of course\n";
}The above is an endless while loop. Perl's for loops can be emulated with a while statement using the continue statement. The continue statement in Perl is not to be confused with Python's continue statement. Python's continue statement ignores the rest (after "continue") of the loop computations and jumps to the next loop iteration, like a break of the current iteration only. The following example script will keep on printing "1". Code: while 1==1:
print(1)
continue # back to the start
print("this is not output")In Perl, the continue statement defines instead an action block to be executed at every loop iteration, no matter how the loop goes. Code: $i = 1;
while ($i == 1) {
print 1;
next;
print 3;
} continue {
print 2 . "\n";
}The last statement is actually the same as Python's continue statement. The output of the above code would be: Code: 12
12
12
12
12
...As you can see, the continue block is executed before the program goes to the next iteration. That's not the same for the last and the redo statements. Perl has three loop control statements: next, last and redo. last is the same as what is the break statement in many languages. last stops executing the loop at the current point, dropping any commands to execute before the loop may end, in the continue block and drops out of the loop as well. Code: while ($i == 1) {
print 1;
last;
print 3;
} continue {
print 2 . "\n";
}The above script would output "1" and then break. Code: 1redo works a bit like both last and next. It breaks the execution of the current iteration without executing the continue block (like last) and it goes back to the beginning of the loop's main block (like next) without re-evaluating the loop's condition. What this means is that even if the condition for the loop to exist is not respected anymore, the block will be reiterated anyway. The loop control statements can be used in any kind of loop. Code: for ($i = 1; $i < 2; $i++) {
$i++;
redo;
}The above will execute endlessly, as there is no condition for the redo statement to be executed. while supports the do while form as well: Code: do {
# what you wanna do
} while (stuff happens)Just like in PHP's while or in the for loop, Perl supports variable declarations in the while condition block. Code: while ($var = 1) {
# this can be more likely useful while handling arrays
}The until loop stays to while just like unless stays to if: it executes the block until the condition is false. Code: until (1==2) {
# endless loop
}The foreach loop can help iterating through the elements of an array without having to manually pick up each of them. Code: @arr = {'foo','bar'}
foreach (@arr) {
print "$_";
}The above script will output "foobar". Another use of foreach might be to iterate through the elements of an hash as well, but as we didn't see anything about Perl's hashes yet, we'll leave this out (I might add it later). Note: Perl's hashes are like associative arrays (i.e. tables). Even though the foreach loop was the last loop we'd find, we still have to talk about the goto statement. The goto statement might constitute actual loops, but it's not a loop procedural structure. The goto statement is just a coarse procedural jump. In my opinion, the goto statement should (or at least could) be removed from any language but Assembly, machine languages, strict "low level" system shell scripting languages (with "low level", here I don't actually mean low level languages, but literally sloppier languages) and, Visual Basic (the reason for this latter is that it's a mostly shoddy language, good for beginners and people wanting to experiment rough coding structures). All though, Perl has a goto statement, and so here I go to explain it: Code: LABEL:
# this is a label. in VB and some system shell scripting languages
# labels are defined by a colon followed by the label name
# in Perl, it is defined by the label name followed by a colon
if ($conditionToBeRespected) { # this is equal to
# if ($conditionToBeRespected == true) {
goto LABEL;
}Let's pretend the condition is always true: Code: $conditionToBeRespected = trueThis is in fact an endless loop. The program will run like this: Code: LABEL
IF TRUE THEN GOTO LABELWill soon update the thread with the following chapters: // FILES HANDLING RE: Introduction to Perl - Psycho_Coder - 07-06-2013 Very well presented. I loved it. Its a good read and you explained each and every point clearly and explained the simple but important things well, your examples were cool. Code: @arr = qw(9 / 10);
print "Your Score : ",@arr ;RE: Introduction to Perl - Psycho_Coder - 07-06-2013 Very well presented. I loved it. Its a good read and you explained each and every point clearly and explained the simple but important things well, your examples were cool. Code: @arr = qw(9 / 10);
print "Your Score : ",@arr ;RE: Introduction to Perl - Psycho_Coder - 07-06-2013 Very well presented. I loved it. Its a good read and you explained each and every point clearly and explained the simple but important things well, your examples were cool. Code: @arr = qw(9 / 10);
print "Your Score : ",@arr ;RE: Introduction to Perl - noize - 07-06-2013 Thank you, Psycho. I updated the OP. Added something more about arrays; added algebrical operators chapter. Less remarkable edits also in other parts. RE: Introduction to Perl - noize - 07-06-2013 Thank you, Psycho. I updated the OP. Added something more about arrays; added algebrical operators chapter. Less remarkable edits also in other parts. RE: Introduction to Perl - noize - 07-06-2013 Thank you, Psycho. I updated the OP. Added something more about arrays; added algebrical operators chapter. Less remarkable edits also in other parts. RE: Introduction to Perl - Boomslang - 07-06-2013 Great tutorial thank you
|