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

Perl Lesson 3


4m read
·Nov 3, 2024

Mids 101 here. Today, it's going to be another Perl lesson, so let's get started by typing in and editing a program I've already pre-made for you. Okay, so here it is, standard Perl stuff. As you can see right here, pretty simple code.

Okay, so now you can see a few things in my code. First of all, I did while true print "hi"; then a close curly brace. I'll just be demonstrating this to you by running this program and showing you what happens. So it keeps on printing out "hi." Now, why is this? Because I've done something called The Loop. A loop is something that keeps on, you know, doing one thing. For instance, if I kept on saying "hi" in a loop, I'd just be getting "hi hi hi hi hi hi hi." You probably know what a loop is already.

Um, so I'm going to be showing you how to do a loop in your Perl program. Let's get started by editing it now. It’ll see while (true) { print "hi"; } simple enough. You'd say while, and then you type a condition in here. I could do something other than true. While true just means do this while life is true is just a piece of crud.

Um, I could also, instead of true, do in here 3 == 3. That just means while 3 equals 3, do this. That means it'll do that again and again and again while 3 equals 3. Actually, when I do 3 equals 3, I have to do double equals, but whatever, and it'll keep on doing that.

So I can also put in here a condition. Watch this: print "Enter your name"; name = standard input; chom(name). Okay, and now I can say while $name eq "Alex." So it'll keep on printing out "hi" while my name is Alex. So I'll just type "Alex" is my name, and I'll keep on doing that. Press Ctrl+C to get out of there, by the way.

Now, to type my name, and I just typed some random crud, it hasn't done anything because it hasn't even entered that loop and begun to loop because my name was not Alex. So now let's try to do one more thing. Let's, um, just go down here.

Okay, so now we've done this. Okay, so what we want to do here now is we can do a few things. Um, we can just get rid of this name equals "Alex," or what we can say is, "while name not equal 'Dave.'" Let me just explain this. I've never said this before in an if statement or while loop or anything. If you have, you know, $name eq "something," you can also have "ne" instead of "eq," which stands for not equals instead of equals.

So I'll just say not equals "Alex." So now, all my name is not "Alex," it'll keep on doing that. Now, we can use this for more proper usages, like "Enter a command" and then $com = standard input; chom($com). Okay, and then let's do system($com). And then I'll say while $com doesn't equal "exit."

Okay, so now I can run this. Enter your name. I don't care what my name is. Enter a command. Now I can type "ls," and I'll do that. I can type "ls -lR /," and it'll do that. I can enter a command; it'll do that. But when I type "exit," it'll get out of the loop. You know why? Because the command that I'm processing is $com, and I said while $com doesn’t equal "exit."

So while $com doesn't equal "exit," if $com does equal "exit," it'll just get out of this loop. At the end of this loop, I'll just have it print "Exiting... Goodbye!" Okay, I'll put a few stars there just to make it official.

Okay, so, um now I'll just do $name. So now, I'll run "hi hi." Enter your name "Alex," and now it says "Enter command Alex." I can do "ls." I can do "ls /users/Alex/Desktop," and it'll show all the documents on my desktop, as accurately, you can see here.

Okay, um, so also you can, um, I'll just type "exit." You can add a condition here, so I'll get into this in my next tutorial, but just in case you care at all, after you do like $com not equal "exit," after that, you can do a space, insert, and then Ampersand (that is shift + 7), space, and then another condition.

I'll do $com not equal "quit." So it'll do this while $com doesn't equal "quit," and $com doesn't equal "exit." Now, $com can not equal "exit" but equal "quit." And actually, I need two shift sevens in there, two Ampersands. Anyway, so $com right here needs to either be "exit" or "quit."

If I've typed "exit" or "quit," this will do it while it doesn't equal it, and it doesn't equal "quit." So if it equals one of those, it'll just go out of the loop. To demonstrate this, of course, I will run it. Enter your name "Alex." I can type "ls." Now I can type "quit," and it's quit. I can also type "exit," and it's quit.

So that's just how to conveniently do a while loop. All the code for this description I believe will be in the description. Um, um, so thank you for watching, mates. Um, subscribe, and um, goodbye.

More Articles

View All
Why Is Yawning Contagious?
Hey, Vsauce. Michael here. And today we’re going to talk about yawning. Why do we yawn and why is yawning contagious? How come when I see someone yawn or even think about it, it makes me kinda of want to yawn? First things first, definitions. When you y…
Sin City's Deadly Vixen | Underworld, Inc.
One breed of hustler exploits this weakness to devastating effect. I’m about to go out and get me some money. I’m about to find some guy that wants to me, and I’m going to get him for all that he has. Vixen is a thief who POS uses as a prostitute. She get…
Microwaving Grapes Makes Plasma
Almost eight years ago, when this channel was fresh and before I had gray hairs in my beard—in fact, before I had a beard—I made a video showing that if you take a grape and cut it almost completely in half and put it in the microwave, you can make some p…
How he bought a Lamborghini Huracan: Chatting Real Estate with Bryan Casella
What’s up you guys? It’s Graham here. So if you guys watch any sort of real estate YouTube videos, I’d say like 99%, you’ve seen Brian Kinsella, which by the way, I think when you type in real estate in YouTube, Brian Kinsella is like one of the first res…
Interpreting direction of motion from position-time graph | AP Calculus AB | Khan Academy
An object is moving along a line. The following graph gives the object’s position relative to its starting point over time. For each point on the graph, is the object moving forward, backward, or neither? So pause this video and try to figure that out. A…
Nihilism: Embracing the Void of Existence
As far as we can observe, being ‘alive’ means that, for a limited amount of time, we’re beings in a mysterious universe, doing whatever we do, seeing, hearing, smelling, touching, tasting, until we die. Animals and plants seem perfectly content with this …