Perl Programming - More Advanced Perl Programs Part 1
Get the entire Perl Programming course for 20% off: http://stoneriverelearning.com/courses/perl-programming-for-beginners-online-course?product_id=38639&coupon_code=YOUTUBE20
In this lecture, I’m going to show you guys more advanced Perl programs, so let me jump right into it. I’ll start off with locating where our Perl program is. #!/usr. Always remember for you Linux and Unix and Mac OS X lovers, never confuse the usr with the word user because we’re locating the direct path where our Perl program is. So after #!usr/bin/perl. Again, with this line of code, it’s just locating where our program is to use with our Perl application.
Now, in our further lectures, we’re not going to be using this line of code because I’m going to show you another way to open up our Perl applications without using this, but this is just good practice for using Unix machines and other Linux operating systems. So our next line of code, I’m going to type a print instruction and I want it to ask us what is the weather today. So in this Perl application, it’s just going to ask us the weather, and based on how hot it is or how cold it is, it’s going to tell us what type of clothes should we wear based on the weather.
So our next line, I’m going to create a container called weather. Again, all this does is it just asked us for the input or we want some data from the keyboard and we want to save that information from the keyboard into a container called weather. Again, I’ll go over this in our further lectures in explicit details. After that, I want to create some logic. I want my Perl application to have some smarts to it, some decision making. Let me take this container. I want to say if the weather is less than or equal to 60 degrees, I want to say “You should wear long pants and a long-sleeved shirt today.” Let me just give it some new lines of space I want to create more decisions because our advanced Perl program is really smart. It thinks like a human. I’m going to ask again, if the weather is greater than 60 degrees and if the weather is below or equal to 75 degrees, you should wear short pants and a t-shirt today. I’ll create another one. Just giving my Perl program some logic. You’ll get into the habit of copying and pasting because it saves you a lot of time. Let’s say it like this. Let me change the 75 to 95 degrees. Let me change this to if the weather is greater than 95 degrees, tell the user it’s too hot to leave the house. Let me save my work. Let me run it. I’ll press F5.
What do we have? What is the weather today? I’ll type a number below 60. I’ll type 50 degrees. What do we have? You should wear long pants and a long-sleeved shirt today. Let’s run it again. Let’s type a number greater than 60, so let’s just type 69 degrees. You should wear short pants a t-shirt. So it’s not too cold to wear shorts and a t-shirt today. Let’s run it again. Let me type a number greater than 95, let’s say 150 degrees. Wow! It’s too hot to leave the house. Let me show you a little bit more. Let’s give a number in between 60 and 95. Let’s just say 89 give or take. You should wear shorts and a t-shirt today. So it’s still okay to wear shorts and a t-shirt today. So I’m just showing you guys a little bit more of an advanced Perl program with a logic. So based on the user input or what we tell our Perl application, it analyzes it and it gives us a decision and an answer based on our input. That’s another more advanced program which I’m going to explain in details in our further courses.