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
Self-Discipline is Freedom... From Yourself. | Why it's Important.
If you have been following this channel for a while, you might get the idea that I like structure. And I do. I love productivity, organization, order, and I try to be as disciplined as possible. When some people hear, they think that it’s boring. They equ…
Meru: Filming the Epic Climb | Nat Geo Live
We called this talk “The Making of Meru” to try to give you guys some insight on how a story like this, you know, a climb like this of rather epic, historic proportions can be translated into a film for a general audience that may have absolutely no knowl…
Passing Obama’s Stimulus Bill | Obama: The Price of Hope
NARRATOR: Obama needs just two Republican senators to defy their party. He turns to the veteran leader of the Senate Democrats. None of the Republicans who wanted to do something to help wanted to be the 60th vote. So I had to get 61 votes on everything. …
Watch: Putting a Camera on a Whale Shark | Expedition Raw
I’m out here putting Critter cams on whale sharks and hope to better understand their behavior along the reef. We spot a shark; it was coming up to the boat and actually very curious. I didn’t really realize where the shark was. As soon as I jumped in the…
The Stickiest *Non-Sticky* Substance
This is one of the strangest materials I have ever seen. It is not sticky at all. You can’t even stick regular tape to it. But if I drape it over this tomato, it holds it up, unless you turn it upside down, in which case it just falls off. Now does it onl…
Sonic Postcards from The Appian Way | Podcast | Overheard at National Geographic
That was our first experience with an unpassable section of the Appian Way. We were with Ricardo at that point. Ricardo told us the path is not clear, so probably we have to cross the river. But let’s see. Writer Nina Strolik and photographer Andrea Fraz…