yego.me
💡 Stop wasting time. Read Youtube instead of watch. Download Chrome Extension

Perl Lesson 2


3m read
·Nov 3, 2024

Processing might take a few minutes. Refresh later.

Hey guys, this is Mids, and on with Perl lesson two. This is the last Perl lesson I'm going to do, and I'm going to rush through it because right now I know that a bunch of you who are watching the summer agenda are just dying to get to Objective C, and you don't want to have to sit through Java next.

So, I'm still going to do all the Java lessons in the same order, but I'm going to start making the videos faster so that way you guys can get to Objective C quicker. This is just another Perl lesson, and it's going to be the last Perl lesson. I'm not really focusing on Perl since I know all of you are just dying to go to Objective C.

So first of all, here's what we're going to do in this Perl lesson: we're going to get a string from the console, we're going to check and see what it is, and then we're going to loop it 10 times and we're going to print whatever they type in back out to the console.

So we're going to open Terminal because we make all Perl apps with Terminal. So I'm going to see you to my desktop. I'm going to V or VI or Nano, and by the way, you should have watched our other terminal lessons before watching this one, so just search "terminal lesson one" on our channel.

Okay, so I'm going to VI input.pl. So now we do the code that we always put at the beginning of every Perl script: #!/usr/bin/perl. Now inside this code, we're going to do a few things. We're going to, like I said, do a loop. So I'm going to say $i = 0; Semicolon. On the next line, I'm going to say while ($i < 10) {. This code right here is going to run while the number $i is less than 10.

Right now it's zero, so what we're going to do at the end of this code every time is we're going to say $i++; and that adds one to the integer $i. So this is going to run technically 10 times because when it's nine, it'll run, and when it's ten, it won't run, and it'll go to the next code after this closing curly brace.

So right in here, I'm going to say print "Enter directory to read: "; Okay, and we're going to say $dir = <STDIN>; So we're reading a line from standard input. Now we're going to do chomp($dir); so we're getting this input from the console.

Now, here's what we're going to do with it, it's magic. We're going to do system("ls $dir");. So system is a new thing; system actually runs a command in Terminal basically. So ls $dir is going to just display the listing.

Now I'm going to say if ($dir eq "/") { and here's the interesting thing: when you're comparing two integers, use ==, and when you're comparing a string to something, use eq. So this is where it's special. If $dir eq "/", then I'm going to use the curly braces again, I'm going to say print "Nice, you're viewing /";.

So it's going to run a command in Terminal. If they type /, it's going to print "Nice, you're viewing /" and it's going to ask them for a directory to read, and it'll do this 10 times. Then after that, it's going to say "10 is up. Goodbye";.

So now we're going to run this. So I'm going to say perl input.pl. So, enter directory to read: first I'll type /users. Okay, next I'll type /, and it'll say, "Nice, you're viewing /."

So this is our reading program. So I'll just do it a few more times, and it'll say "10 is up. Goodbye." Okay, so this is our Perl script. It's very not limited, so if you really wanted to learn Perl, this is not where you're going to go.

I was just using Perl as an example so that way when you do PHP later on, you'll be familiar with it. But those of you who want to rush through to get right to Objective C, so I'm only doing two Perl lessons, and this is very cut back. I have three other Perl lessons that weren't quite as g...

More Articles

View All
The TRUTH About Tesla Model 3 After 1 Year... (w/ @LudicrousFeed)
Hey guys, welcome back to the channel! In this video, we are talking about the Tesla Model 3 because recently my good friend Tom from Ludacris Feed was down in Canberra, and he reached out to me. He said, “Hey Brandon, you want to go for a drive?” You guy…
Using matrices to transform the plane: Mapping a vector | Matrices | Precalculus | Khan Academy
Let’s say that we have the vector (3, 2). We know that we can express this as a weighted sum of the unit vectors in two dimensions, or we could view it as a linear combination. You could view this as (3) times the unit vector in the (x) direction, which i…
Writing decimals and fractions from number lines
We’re told to express the point on the number line as both a fraction and a decimal, so pause this video and have a go at that. All right, now let’s do this together. We can see that the point in question is at a higher value than four and less than five…
Missing numbers in addition and subtraction | 2nd grade | Khan Academy
Let’s say someone walks up to you on the street and says, “Quick! “73 plus blank is equal to 57.” What would blank be? Well, there’s a couple of ways to think about it. Blank is essentially what you have to add to 57 to get to 73. It’s the difference be…
Homeroom Office Hours With Sal: Tuesday, March 17. Livestream From Homeroom
Okay, I think, uh, third time did the trick. Sorry for all the stops and starts. As I mentioned, uh, this is all very, um, impromptu and very improvisational. But yes, now even this dashboard that I’m using says that I’m online on at least Facebook and Yo…
7 Tips for Effective Remote Learning with Khan Academy
Hello all! Welcome to Seven Tips for Effective Remote Learning with Khan Academy. My name is Megan Patani and I head up U.S. Teacher Education here at Khan Academy. I’m joined today by my colleague Jeremy, who leads our Teacher Success Team. So just a li…