00:00
Hello everyone. Welcome back to VLSI Academy. This is third lecture on
00:04
part programming language and today we will begin with something called
00:08
Lists in PURL. When we define a scalar variable such as this, it is nothing but a
00:13
list with one scalar variable. When we define an array like this, it has nothing
00:17
but a list with collection of different items. And we define a hash like this.
00:22
It is nothing but a list with different key value pairs. Hence in above
00:26
examples, all three lists are of scalar array and hash type. Hence an array is
00:33
a variable but all of PURL's data type. Scalar array and hash can provide a
00:38
list which is simply an ordered or unordered set of scalars. Moving on,
00:42
generally speaking lists are collection of scalars. This is a list of characters,
00:46
this is a list of integers, this is a list of strings. As you can see, you use
00:52
the parenthesis and comma operators to construct a list. Each value in the list is
00:56
called a list element. List elements are indexed and ordered. You can refer to
01:01
each element by its position. So from now on, we will refer to all the arrays as
01:05
lists only. As this is a common terminology in the PURL platform. Now as we know,
01:12
list is a collection of scalars. Hence it is also ordered and can be
01:16
referenced with the index values. This is how we declare the list and to access
01:22
its element, we just have to specify the index value in the list name and since
01:26
it is a scalar value, we just have to specify the prefix with the dollar. We can
01:32
also access list element from the last. The last element index will be minus one.
01:38
So when you run it in the command line, fourth element of the output will be
01:42
Uma and when the you run the second line in the command line, output should be
01:47
Suresh. Moving on to other features of list is list slicing. So you can assign
01:53
from one array a slice to the other array. So the PURL interpreter has no
01:59
problem with this statement because it copies the list stored in one three and
02:03
five location into a temporary location which is invisible to the user before
02:08
assigning it to the new names 0 1 and 2. So how do you do is first you will
02:14
declare this name list and after that you will assign it to new list new name
02:19
list. So name 1 3 5 will go to new name 0 1 2 and print new name of 1 will give
02:25
output and command line as Manju which is this variable here. That's all for today.
02:31
We will see more features of list in next video. Please share and subscribe to
02:35
the channel for more updates. Thank you.
00:00
Hello everyone, welcome to VLSI Academy. This is fifth lecture and today we will discuss
00:04
about conditional statements in Perl. Consider a case where employees are classified based
00:09
on their salary. If the salary is greater than 10,000, then it will be tagged as manager
00:13
and if it is lesser than 10,000, then you have to tag it as staff. So to write such a
00:18
code first, we will declare the variable salary, which based on which you have to classify.
00:23
And then if condition is written something like this, if the salary is greater than 10,000,
00:27
then print employee is manager. So here we have taken this example just to give you the
00:31
idea how the syntax looks like for if condition in Perl, which is very similar to how we write
00:35
in C. Now, else if condition is something like this, where else if salary is lesser than
00:41
10,000, then you have to print employee is staff. Here you just have to note else if condition
00:46
it is E L S I F not E L S E E I F. So E is missing here, which is very peculiar to
00:53
Perl. Now moving on Perl has a very peculiar feature which is different than other platform
00:58
and that is unless condition, which means that it will execute the statement if it evaluates
01:03
to false and it will not execute and it will exit out if the evaluation of the statement
01:08
is true. So let's say you have a variable 22. So for example, if you want to put unless
01:14
condition with this condition that variable lesser than 20 and if you put the condition
01:20
to print this statement, so it will evaluate this and 22 is lesser than 20, this is false.
01:25
So it will go inside it and it will print and if it is true, then it will not go inside
01:30
it. So strictly speaking, it is actually if along with not statement. So it will evaluate
01:36
to false and if it is false, then it will go inside. Let us move on to very commonly
01:42
use the switch statement, which is present in all platforms with almost similar functionality
01:46
everywhere. For using the switch statement in Perl, first you have to declare the switch
01:50
statement and this is the variable based on which we will choose between the different
01:55
cases which we have to consider. So let's say we have an array and we have a hash. Now
02:02
this is the switch statement syntax where you have to declare this variable inside the
02:06
parenthesis after the switch and with this parenthesis, we will start our switch statement.
02:13
So and first case is case 10 so case 10 if it matches the variable matches to this value
02:20
then it will print number 100. If the variable matches to a it will print string A. If
02:24
the variable matches to this list, it will print numbers discontinuously and if the
02:29
variable value matches to this array then it will print numbering no list. If the variable
02:34
value matches to hash, it will print entry in hash. If none of the matches, then it will
02:38
print else condition. So in C, you will have default here.
02:42
here it is else in the burl and this is the parenthesis close of this switch statement.
02:48
So since our value is 30 so it will go and it will check it is not 30 it does not fall
02:55
inside this list also but it will be array and array is this 1020 30 so it is present here
03:01
so it will go here and number in array list will be printed.
03:05
Let us now explore some of the commonly used control statements which comes very handy
03:08
while writing a program and helps the programmer to write a program easily and efficiently.
03:13
So here are some of them.
03:15
Next statement will escape the remainder of the loop and goes back to the beginning
03:20
While last statement will exit the loop and hand over the execution to the statement
03:25
Redo statement will restart the loop again with the previously tested condition.
03:29
Go to statement transfer the program controlled to a particular label or expression just
03:34
like C programming.
03:36
Let us all for this video we have provided you the basic idea and we will see their usage
03:40
in the real life examples later on.
03:43
In next video we will see the different loops and their examples in the purl.
03:46
Please like share and subscribe to the channel and let us know your feedback in the
03:49
comment section below.