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
Ancient City of Nan Madol | Lost Cities With Albert Lin
[dramatic music playing] MALE SPEAKER: This is it, Albert. Welcome to the jungle. We are on sacred grounds right now. You’re just beginning to see part of the structures. ALBERT LIN: I’ve never seen anything like this. MALE SPEAKER: Welcome to Nan Mado…
Legends of Kingfishers, Otters, and Red-tailed Hawks | Podcast | Overheard at National Geographic
I became completely obsessed with them when I was seven. I have no idea why. I’m fairly obsessive person, and so all of my spare time as a teenager was spent sitting in my blind, taking mostly, in fact, almost all useless photographs of kingfishers. What …
This Is What Happens to Your Brain on Opioids | Short Film Showcase
This is Susan. Susan loves to bike. While out for a ride, she falls and breaks her arm. Special cells called neurons send a signal through the spinal cord to the brain, which interprets the signal as pain. Susan understands the pain means she needs to go…
The Most Iconic TAG Heuer Watch of All Time | Monaco Split-Seconds Chronograph
Hey, Mr. Wonderful here, and I am in a magic zone! This is TAG. Now, this brand is legendary as a sports brand, obviously through racing, the association with racing, but it’s so much more now. And of late, for those of you that collect, we’ve expanded al…
Conventional current
When we start to study electricity, we need to get an idea of what is current and what is voltage. In two earlier videos, I talked about the idea of current and voltage, current and voltage, and what they meant. When we talked about current, it’s easiest …
Later Stage Advice with Sam Altman (How to Start a Startup 2014: Lecture 20)
All right, uh good afternoon and welcome to the last class of how to start a startup. So, this is a little bit different than every other class. Every other class has been things that you should be thinking about in general at the beginning of a startup. …