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

Perl Lesson 2


5m read
·Nov 3, 2024

That kids don't, no one here today. This is going to be Pearl lesson two of our Perl essence. So I'll just get started by working on a Perl script that I have already started. So it happens to be in my documents, so I called it "we", and this time I will be editing it with nano.

So anyway, here's my Perl script. Um, so I'll just, uh, I go into how to do if statements. So they've typed in their name in my little Perl script so far, which I called "the wii", and they've done all this crud. So now that I have their name and I've said hello to them, I can do an if statement.

Now, an if statement checks if something is true or not, so this could just be quite useful to you. So here are the three parts of an if statement: you type if, space, open parentheses, and then you type, um, let's do $chisel, which is the variable I assigned to their name, whatever they take into their name, space. Now I'm checking what it equals, so I'm going to type eq, which stands for equals, space.

Well, let's check if their name is "Alex" close quote, close parentheses. So the thing is, the if statement is going to check for, and there's one more component of the statement: if parentheses $chisel eq "Alex" so that's if it equals lowercase "Alex" with no spaces after it, or anything like that, that's good.

So now after this, we want to do space, and then instead of a semicolon at the end of this line, we want to do an open curly brace. If you don't know what a curly brace is, you should watch my video on keys on your keyboard. Um, anyway, so we have that open curly brace.

So now go to the next line, and we can type on what will happen. So in this case, I'll print out something that says "Dude, you are the best." That's a shame. print "Dude, you are the best";. So that's going to print out "Dude, you are the best" if they type their name as Alex. And I'll hit enter, and I'll do a close curly brace.

And now, say I want to check another thing. I do space, and then I do elsif, except it's all one word and there's no "if" in "else". And then I do space, and then this is like the if. I just do open parenthesis $chisel eq "Gabe" close parentheses. And then I do space, open curly brace.

Now I hit enter and I say "Hello, David;". And then quote semicolon. And now I hit enter and I can do a close curly brace. Um, I don't have to put in elsif, but there has to be an open and close curly brace somewhere along the way.

So I have if $chisel eq "Alex" and then I have this, and then I have a close curly brace. Then I just happened to throw in the elsif after a close curly brace. You can either leave the if statement be or throw in an elsif.

So now I'll throw in another elsif right here, and I'll just zoom into this code so that you can see it better. And I'll also put all the code for this program I made in the description. So I did elsif $chisel eq "John" and then one last thing they type in, if they type "John" will do another open curly brace.

Hit okay, I bet you love photo; now closed semicolon. Now I'll do a close curly brace there. Now say if they type anything else, so I want to do like an else and whatever. So I'll do space else space open curly brace, and then I hit enter.

So after the close curly brace, I do space else space open curly brace. I hit enter, now I'm just going to type print "I don't care about your name";. Now I'm going to do close curly brace.

So I have the standard if statement if (condition) {} that I added in elsif, I added another elsif, and I added an else. If statements can also just look like this: if ($chisel eq "Dave") {}.

If statements can be as simple as this; that if statement is right here, pretty simple, unbelievably simple. I'll also put that simple if statement in the description. But you can also add as many elsif as you want to, and of course, as many ifs. Or there's one if, one else, and you can add as many elsif as you want.

Now, another thing I'll be teaching you in a short amount of time left is how to run a command in terminal from a Perl script. So let's say if it equals "Dave", just go to the next one, then I can type system "killall Terminal";.

Gotta kill their terminal, and that's going to be really annoying. So now let's exit this as I would like to save, and I will just run "we." What is my name? First of all, I'll take "Dave."

I'll say "Hello, David," as I said it to act in the if statement. I've said to print out "Hello, David." So now remember the old trick you put backslash \n at the end of every print if you wanted to go to the next line afterward.

So once again, you "we." Now I'm going to type random crud in here. It says "I don't care about your name." That's because I said in the else thing, if it doesn't equal any of those, to print out "I don't care about your name."

Right here it reminds me, I should add a backslash \n right here. "Michael", ok? And then I can do "run we" again. Name in my program, and now I'm going to type "Alex." "Hello, Alex."

"Dude, you are the best!" John and I killed term. That is because I set it to kill terminal on the typed job. So John is really annoying me now because I quit the terminal.

So I did system "killall Terminal";. And of course, I killed the terminal. I'll just do a better example of a system there. Let's think of one good command that would be sort of cool.

Let me go to my program, okay? So I'm going to edit my program again, and in the system here instead of "killall Terminal," I'm going to do something even more annoying. I'm going to type ls -lr /; that’s going to display all the contents of the entire hard drive.

That's just a command in terminal you can try it out; I'll have it in this description. So now I can run "we" again, and it says "What is your name?" I'll just type "John."

"Oh no!" Get an ls -lr /. So that's why it's so much fun to, um, do a Perl script. You can do a system, you can do if statements, so you can make basically a terminal emulator with the information I just gave you. So I thanks for watching, back as we rock, and goodbye.

More Articles

View All
Setting up a system of equations from context example
In this video, we’re going to get some more practice setting up systems of equations, not solving them, but just setting them up. So we’re told Sanjay’s dog weighs 5 times as much as his cat. His dog is also 20 kilograms heavier than his cat. Let c be the…
Reacting to Myself: Living On $1.6 Million A Year In Los Angeles | Millennial Money
What’s up, you guys? It’s Graham here, and wow, what a time to be alive! We have officially entered the matrix. This is because I was just featured on the show Millennial Money by CNBC Make It. For those that are not aware of the significance of this, let…
Spider vs Penis (Priapism) - Smarter Every Day 98
Alright, so this video may not be appropriate for kids, and it is, uh… It’s disturbing on several different levels. Especially if you’re a man… So, you know, on Smarter Every Day, I try to keep everything very intelligent and respectful, but this video is…
Market demand as the sum of individual demand | APⓇ Microeconomics | Khan Academy
In this video, we’re going to think about the market for apples. But the more important thing isn’t the apples; it’s to appreciate that the demand curves for a market are really the sum of the individual demand curves for every member of that market. Most…
The Helicopter Speed Limit - Helicopter Physics Series - #7 - Smarter Every Day 51
Helicopters have a speed limit that has nothing to do with laws. Well, unless you count the laws of physics. Hey, it’s me, Destin. Welcome back to Smarter Every Day. The show where we do science. So today I’m gonna explain to you something pretty interes…
Khan Academy Ed Talks with Kristi Yamaguchi - Thursday, March 3
Hello! Welcome to Khan Academy Ed Talks. I am Caroline Hu Flexer, the CEO and co-founder of Khan Academy Kids, which is a mobile app for children ages two through eight that’s focused on literacy, math, and social-emotional learning. Today, we are celebr…