 after like two minutes and then just check the audio with the audio hi everyone again welcome to this course on the Linux programming and scripting we covered the first two modules the basics of Linux and then the Linux networking last time we covered the second part of the one of the file system that we were studying you studied two file systems the Sun NSS as well as the Android file system the Android file system is what we covered in the last lecture we also went through all the the differences between the Android file system and the Sanayam okay and we noted certain similarity certain different similarity was that we'll use some kind of a virtual file system manager for the Andrews file system basically goes more like a process running which handles all these virtualization whereas for the NSS we have to mount those file systems separately and then the control was more at the client side for the the NFS system whereas in the server side for the Android file system so the Android file system is more versatile more secure and we also saw that the Android file system we don't need to actually there aren't like many Android file set up basically like I mean so the subnet or subnet work kind of systems are not there whereas the NSS is more distributed as clusters so I mean there are like few Andrews file system based services available today and we also saw that actually Andrews based for some of the standardization that happened in the distributed file system area I just want to keep want to want you to keep that in mind so today we are going to switch gears and talk about the programming aspect of the course so we will be starting with a simple language called Perl and this Perl language is used widely in the industry especially in the high-tech companies in fact lot of software companies also use this particular language the Perl language the hardware companies for all kinds of scripting we use Perl language we will learn about why this is used more widely and what makes it more attractive than the traditional programming languages like Fortran or C or C++ again Perl has many variants but the most significant change in Perl is the recent one which is the object-oriented Perl which we will touch upon towards the end of the this material so let us look at what we have the agenda for today so we will start with the introduction today we will be introducing mostly to the data side of things Perl even though we will touch upon couple of commands because without understanding some basic command you cannot understand the data so we will go through some of the stuff and mostly today we will talk about the scalar data which is essentially a single variable or the variable that holds a single value and then we will have also we will talk about array and list data arrays you can input that as a data structure which has some kind of arrayed scalars or the scalars themselves are there are many scale of data which is arrayed together so they have some commonality they can mean how to index things like that and then we will also look at some of the list with data which is again they are also kind of arrays but they are specialized arrays you can input that way so that's the pretty much what we will do and as usual you know we will talk about how to write some basic scripting in Perl today and then as we go through the course we will progressively increase the level of difficulty and hopefully by end of this module you will all be like well trained programmers in Perl and you can write any scripts anytime with any whatever the specific mission that you given to you again I just wanted to say that the basic algorithms in your writing program they are all similar and probably you have already covered those things for in your undergrad and other courses so I won't be talking about the algorithms as to how to do it we have questions we can always talk about talk talk it over but mostly like I mean we will be focusing on the syntax and the semantic in the Perl language itself so let's look at the Perl just an introduction to Perl Perl stands for practical extraction and report language so if it's a big mouthful actually but people always refer to this as Perl and if for people like I mean who like the language it's they also talk call it as a the ecologically eclectic rubbish list and then whereas like I mean some people who still don't like Perl they call it like pointless exercise in redundancy and just think about it basically only some people they think that that's redundant so anyway depends on which group you are if you are well versed in other languages like C C++ and you are always like hands-on with those languages you won't find this that useful probably will still go towards those languages but if you are more like me who's essentially like I mean I do programming for solving some of my problems then you will like Perl better because it gives you a very easy and very quick platform to do your program on the history front the creator of Perl is Larry Wong so and then the versions got updated with perfect new enhancement and version four is pretty much the standard version that people use and then there is also a new version version five which is more of Victorian so if you look at your textbooks essentially like I mean it will tell you whether it is based on the version four or version five and I would recommend you to actually at least look at the version five books because that has the arbitrary constructs already and then the main purpose of Perl why he developed that is for the Unix user so in Unix you get like two kinds of program that we saw already one is this shell scripts which we touched upon it briefly as to how to do like from shell scripting with the various commands so the arc depth all those things basically that we can use it in shell scripts the shell scripts are cumbersome to write and they are not really portable so that is one reason they are looking for a formal language the formal languages like C and other languages are complicated they are strongly typed languages it is not really useful for people in other areas like say for example VLSI design to do some program so in VLSI design as you know we want to augment your work with programming other than the programming itself becomes part of the main work so in that kind of scenario you need lightweight language which has some formalism not like a script but at the same time you do not want like too much formalism like any other language so that is the reason why people want opted for Perl so here is a simple script essentially like I just wanted to highlight few things here so we know these things basically one is hash bang as bang is essentially to tell the your shell that whatever is following that in the file is a script then we have this user been perl which specifies the path to the Perl executable which now like uses this as a main interpreter and then then it starts basically in Perl these are all like constructs in Perl so this itself is a command and then followed by arguments and here notice that the code here the thing is under the inside the code and then there is the backslash n and then at the end there is a semicolon so I just wanted to to just observe these things at this point you will come back to it in a while as to why they are what is the significance of each of them again in this state this one again this is another print statement say what is your name the code and the semicolon and then we have another special stuff which is this dollar sign and then name and then again here also there is another special stuff less than and greater than and then there is something in between which is sjdin and in here there is another command chop command for this one there is no the semicolon but instead there is a there are parenthesis and then plus there is the dollar name the same thing that appears okay and then finally another print statement with some more arguments so if you look at this particular statement this may be like it may be familiar with this construct which is very similar to like a field construct where you are calling a subroutine with a subroutine name and an argument and if you just leave this as blank then you know that there is no argument to that so anyway we will come to this in a minute but so this is a simple program what it does is this we will see in the next slide what exactly do so here we can execute this program in the unique system again you know some other things basically but again here you know that actually the percentage is the shell that stands for the shell and then you basically type in the hello.pl which is your Perthaman and before you give this you need to make sure that this is the execute permissions are set that is the change mode seven seven seven more same mode at least some one at least you can have one there or plus x with this file name so that you can execute it directly and here the way it works is essentially it prints out this hello world this is the first statement that we saw and then it goes to the next line and then ask for what is your name and then it waits for the user to input this portion so the user types in this name immediately it is a welcome the user so we saw that actually like this particular input is captured under dollar name and then the dollar name is what these are the things that we saw in the earlier program right and so let us see more about Perth itself so if you are running it on the pc actually then you have this keyword Perth and then you can actually run the Perth with the command here it is called ex01 but it could be also like hello about Perth in the same thing it also does the same stuff this you can run it within a terminal in cycle windows and then there are a lot of versions available to install Perl versions available that you can install and then run it so now let us talk about some simple rules that in Perl that we will begin with so number one is Perl is more like an interpreter so in a compile language like C or C plus plug you have to first compile the program into an executable and then the executable is can be run and then executable is cannot be read by humans read by humans and it is more like it is machine for and there the compiler does a lot of optimization to come up with the best possible which also has minimize the runtime and things like that so the compiler course is a separate course and essentially I urge you to take it when you get a chance because that will teach a lot of techniques that the modern compilers use to eliminate redundancy and eliminate loops and things like that but for Perl actually you can think of this as an interpreter it interprets line by line and then basically executes this line directly it does not need to generate anything in intermediate format and this is a great help because this is the one of the reasons why engineers like this especially electrical engineers like Perl because it is more like what you see is what you get basically you can just forward the program and just run it that is it basically you do not need to meddle with it you do not need to compile it you do not need to optimize it whatever you write immediately execute so that is one good thing and then Perl is also a pre-format language so essentially the format is not dictated by where the white spaces or how the white spaces form so so you can actually use white spaces freely if it is one white space or many white spaces it does not care the as you have seen like the earlier example the commands are terminated by semi-colonial that is the reason why the put semi-colonial command and essentially like the indentation of programs we do it only for human readability purposes it does nothing to do with whether Perl needs some indentation or something you will see that there is some difference when we talk about language like Python which is not a pre-format and then basically there the white space means certain things even in tickle actually the white space means something so we will see like that put white space where not to put white space in both those languages the coming sections coming weeks but right now I wanted to think about Perl as a pre-format language and you can use white space for totally free and then another thing is Perl just starts executing from the top just one by line by line it just goes on going on there is no concept of a main so whereas like coming in language like C actually always only the main routine will get executed wherever it is if it is in the last section it just executes the name from the classic and then essentially inside main you can put a lot of functions subroutines and then basically do that that subroutine and actually running it as subroutine is still supported in fact some of these the Perl libraries themselves comprises of lot of subroutines for various for example this the chop command that we saw it is a classic subroutine type of a command essentially which may be like then split it into multiple different other commands and then that may call some of the commands which essentially serves as the chop function we will look at what that function does starting so just wanted to let you know this one and then let's see some more to incorporate comments actually the comments start with a hash time and then they continue until the end of the line so every line which starts or at some point there is a hash is treated as a common line only exception to this rule is the first line which we saw that actually it started with the hash bank the hash bank itself is together with one command which tells the the program that hey this is the it identifies this particular file as a Perl program so that is the only reason why we use that and that needs to be the first one so that is only restriction there so anything after that hash until the end of the line will be you know so you can actually put a hash at the end of a particular command once you close the command with a semicolon you can put a hash and write what the command does and it is perfectly legal in Perl only thing is like you need to make sure that the command is closed there are some commands actually like I will take it back in any cases you can start with a hash and just continue the only restriction is when you are mixing many languages together like the typical with Perl and things like that there you need to follow some additional rules but in the pure Perl language anytime you start inside the line with the hash whatever is the remaining until the end of the line so in C actually we have these multi line commands I think like you must be familiar with that basically like in C we can do this form like put a slash and then star and then blah blah blah blah blah and then put another star and then a slash the center thing is a command in Perl actually it is not like that basically like we need to do the hash and then whatever is that line is one command and then another hash so they cannot be just combined so just wanted to be aware of that and then the other rule in Perl language is that the names are all case sensitive so the upper case name and lower case name this is so again that if you are writing a program make sure that you stick with one case and essentially like you have to that is the only way that you do and the per program itself consists of several statements we already saw like at least three types of statements the one was the print statement the print actually had an argument with it folks we will see why that and then we also saw the chop command which is basically the argument was within a within parenthesis then the third type is that we saw was an assignment where we say like the dollar name equals to less than stdin greater than that is another type of statement so we will have like several of them basically we will use more number of statements as we go through this lecture and then every statement is terminated by some column so that is the reason why also like I mean this is the language itself is format free because the you can terminate the end of the statement is only determined by different form so the only exception to this rule is when you have comments so just keep that in mind or when you have the command which is like starting with the hash you do not need to terminate it with the semicolon because it is technically not a statement so some more rules so the general format of any statement will be an operator I followed by a number of arguments and usually the arguments are included within the parenthesis so but some sometime we can actually or even most of the time we can eliminate that so you do not have to actually specify the pattern and the anything that is within double quotes is a string and it is stored similar to see basically it is stored as a string string is also an array of characters you can say and then Perl itself does not impose any built-in limit on the size of the string but sometimes you are the regular operating system can impose some limits so you have to when that limit is reached actually as the program so the thing is basically you can read the entire book like all the characters inside the book as a single string so you can think of your Perl book which probably has like more than 500 pages and from the beginning of the page to the end of the page the entire string you can just when you entire character set you can think of that as just a single string inside but provided the operating system allows so Perl itself does not put any restriction but the operating system and there is also a single quoted string you will see the distinction between the single quoted string and strings with double quotes in a later stage I do not want to tell you the all the things at this point and then the biggest advantage with Perl is there is no need to declare anything and this is one of the reasons for big reasons why people love Perl in other languages so if you do not declare and start using a variable the program will start complaining basically saying that hey you haven't located that variable you cannot use it used by a company else so it can actually do some whether the particular variable is live and things like that some kind of analysis program here in Perl you can just use it as you go and then basically the tool will figure out how to find this variable so one portion I will say is I still recommend you to declare the variables at least set it up what variables that you are using in within a program at the beginning of the program the reason is just to improve the user readability because you may use some certain algorithms certain things and the person who is actually reading it may not understand what kind of variables you use there so it will be a good good idea a good practice to actually declare it upfront and then use them basically so again it does not impose there so maybe like things like loops and stuff like that you may not need to declare those variables like or I equal to 1 to 10 or something I you don't need to define that but in any case any other situation like you are doing an algorithm and you have a way to solve the problem that those variables if you specify it up then that really helps the next person who tries to understand how you wrote the program and then the other thing that we saw about this dollar sign in the first program so any scalar variable is started with that dollars so if you write a dollar name dollar x y v any other kind of dollar something well knows that that is a variable so and it is also it is a scalar variable means like that variable can hold only one and then the backslash characters they are they are similar to free program so for example the backslash in the new line character the backslash T is the tab so you can actually create it like a lot of these backslash characters even special characters if you want to make them make sure that they can print you need to make sure that that that is a escape with the backslash so we just probably escape character but it is the backslash then there is a concept of file handlers and there are some standard file which actually comes by default with call installation the standard file handlers are a city I am a city out a city ERR and ARG the STD in stands for standard in which means that the file that is basically there whatever you are typing in the keyboard gets logged essentially it is not logged actually that the file that operating system uses that files address is the standard in and then the operating system wherever it puts out the particular file or as an output that is the standard out and then there is also like an alternate method that operating system uses to produce some output the reports basically that is the STD ERR or the standard error that can also go in there and ARG is a generalized file handler for getting some data so you can actually put like the and this is basically we will see like and are the values that you can input and it figures out the how to get values so here anytime we assign the standard in to a variable it grabs the line of input so the entire line is taken from the input and then assigned to this STD so if you think about it basically including the new line the next line going to the next line everything is captured and dumped it into this STD IN so we made a scalar variable called the name and then we made that equal to this standard in so whatever it standard in is reading that is what goes into the scale again you may be confused because bring itself as I told you it is just an array of characters so how can you assign a string which is more like an array to the variable or essentially just a scalar data which is only one wrong the way we do it is essentially we always treat them as a string and we do not let them wander off rather go out and basically or separate them into like characters then themselves and then basically that is not what we are doing we always treat that as a single singular entity so that is why you can still use a scalar variable represent more because the scalar variable is now pointing to a single entity and finally the the last command chop here we just specify like chop in parenthesis s so s is the argument for chop command and here the s because like the chop command is used chop command removes the last character from the string from the string yes so so this is a useful command there are there is one more way to actually remove this the last character we will learn about that the future lecture so this is the example that we saw so now like I mean it is much more clear there is the the commands so if you look at it there are three types one two three because the three types of statements the first statement is a print statement basically which is just an output statement that output something the second statement is more like an input statement basically it gets it waits for std in to be input and then basically assigns it to the name and then third one is more like an operational statement which is within the program itself which is form it chops the last character from power which is typically the new line and then finally the print hello is the output one which as it as it goes basically prints the dollar name which is this the variable that holds whatever you factor so play with it I think this is a good little exercise that will help you hone in some of the skills so before we go into the variables themselves the scalar variables and the anti variables in more detail let us look at one statement and then we can move on the statement what we have is if else is else statement so notice that there is there are no and then yeah so the way it works is again here we start with the statement higher or a and then in the parenthesis we specify the argument for this you know which could be like either equality inequality or some logic function we will see like what kind of logic function that we can use here but again the way it works is the condition if it evaluates to a one one in Perl is what is called true and then zero is false if it evaluates to one then you can put whatever is between these two brackets so this this code will get executed if this one is not evaluates to a zero then it goes into this loop in this loop actually like there is a parenthesis that is missing here so you think of this as more conditions here so using the parenthesis it evaluates and finds out whether again if it evaluates to zero or a one if this happens to be a zero again then it switches and goes to this L if you look at here basically there is no else so this is the catch all condition there any anything that fails to execute in these buckets will get executed at least here so this is like a small example of an if statement we will go into more details and more complex examples so let us look at the operators that I mentioned basically the operations can be performed in two ways one is a numerical operator which is performed on numbers just like one greater than two or one less than two things like that where both sides evaluate number then we can actually compare them with these operators so the numerical operators are w equal to less than greater than less than or equal to greater than or equal to not so look at that actually for the the equal to testing is using two equal to if you do only one equal to basically it is an assignment statement it is no longer logical testing say similarly at the string level actually can do an EQ less than greater than less than or equal to greater than or equal to not equal to so this is again another way to express that information so here it is a little bit more complex complicated example with the things that we learn which is if else is else so here also it starts with the same things basically the user local bin poll we want to go into that details that detail for this but here this portion is pretty much the same as the previous example which is like if you print your name then it waits for the standard in and now if the name so let us look at the remaining stuff as to what is going on so if the dollar name equal to a particular person with here it is Stephen then it will print welcome Stephen if the name is equal to Jessica then it will print how are you Jessica and then if it's up and there is none of the above then it will print hey what are you doing here maybe like I mean this is not your computer and you have more doing anything with it so that is a that is another way that you can use so now we will go into the arrays so array variables as I mentioned you basically mentioned to you it is basically it is a collection of scalar variables and array variables typically begin with an ampersand as opposed to a dollar for the for the scalar variables so again we know that actually the Perl is case sensitive now we are adding one more essentially like I mean the same command they exist basically like they are actually two different amounts two different variables for example here the dollar name here the dollar name and at dollar name they are two different variables they have different meanings and they can be completely different variables so a small example here which is at name equals to Adam Bob and Chal then chemical so here you can see that basically this is the the name or the array name and then this is the array declaration that is it is Adam Bob and Chal let us look at how to retrieve this array okay before so we will figure out like how to do how to retrieve this when you do the actual program so but let us look at associative array because this is another key area that that will be used and a lot of times basically so associative array is kind of an array which does not have integers or numbers as index essentially it can have actually different in the indices whether it can be just a number or a numerical value or any string anything can be used as a key or actually as a key or the index of that array so again one thing is for this type of array you have a key instead of the actual index you do not call it as an index you just call it as e and then basically it need not be numerical so those are the two things that I want you to remember now let us see like what happens so it uses a prefix percentage for the associative array instead of this add symbol and then so the simple array could be this percentage student equal to name David height 6.1 degree PhD so the way to read it is basically the first one is the index the second one is the value or we will even call the index what the key and then the second one is the value so in this case essentially again the percentage student or the student array consists of three fields first field is the game second field is the height and third field is the degree and then it just think assigns these values to that particular location so if you say like student name then that will that will that will give you the output as David for example before I mean it is not even go there so we can also like refer to as just this out you can say percentage student then specify it as and this will be given as this day its height again same thing height and then it will come up with this point you say degree then it will print PhD second this is a very useful concept essentially as I told you like I mean this is used by many many programs and many tools essentially for getting some clarity also like doing some difficult algorithm for example you can write a code for finding the timing violations the top 10 timing violations in a survey and you have a full every report possible and then you can write a small first step to be through it and then find the 10 first unique path violation from the file if it is a basically you need to understand the pearl and basically like what is the syntax in which it is publishing the various timing paths and then we need to go and do some more massaging of that in order to get that information out and we will actually like looking we will be looking into this associative array in a big way because this is one of the key concepts that you should have so in C and other other programming languages there is a concept of hash as a race but this is very similar to that concept you can think of it even though the ashes are dynamic hashes you can say like from various from the data structure to data essentially so I think like I mean I am going to leave you with this for today because what we will be starting in the next class will be mostly like how to do the programming itself using these data structures so just to recap we went through this variables so today as I mentioned basically we will be talking about the scalar variable so we first talked about the regular scalar variables like the $ name so any scalar variables begins with the $ and then followed by some characters and this character is case sensitive there are a couple of ways of writing this the variable name one is the basically like every word is separated within underscore so and then make those words meaningful of what is in the program or you can also try to use camel case which is basically capitalized the the second word onwards essentially first word alone stays at lower case but then for the second word the first letter will be uppercase and then followed by low so so you can use that to as a variable name I will let you choose because some people like to actually do the underscourcing which is which was very prevalent in 80s and 90s also in 2000s but then with the advent of the other programming languages and people when they became familiar with that like Python and things like Python and tickle especially they started writing it in camel case so I will let you choose whichever form of that you want to use but just be aware that once you choose a format pretty much it will stick with you for your life so I don't know if it just happens so it is very hard to change in the future time so I choose whichever one that you want but be consistent that is that is my message so that is on the scalar side then on the array variables because actually the array variables are starts with an at symbol instead of dollar and the dollar name and at name are completely like two different variables and in the dollar at name the way that we specify is we write out the all the values that that particular array can take into that in a straight line in this example we are using like a we are using names or strings as an example but this could be just numerical values that is also possible and here like string you can see that actually with the ports also the double quotes and then finally we saw the associative array associative array is a type of a data structure which gives like more makes it more versatile for well in fact one of the concepts is essentially once you know associative array and the regular expression which is another thing that we will talk about you are pretty much covered for well then you can actually write some really really complex programs by just understanding these two sets essentially which is the associative array and and the regular expressions. Let us see so for the one thing about this associative array as I mentioned essentially it has the key value pair essentially like that is what we call it all this this particular unit this unit is together and they are called the key and then value so if you do not a key then it basically less than the value so and then the the key can be like anything basically this numeric keys can be just some strings however you want to build it you can build it essentially there is no one way to do it so I think let us conclude at this point here we can pick it up in the next class from this point onwards okay thanks