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
Warren Buffett: Buy These Inflation-Proof Businesses
Well, the businesses that will perform the best are the ones that require little capital investment to facilitate inflationary growth and that have strong positions that allow them to increase prices with inflation. And, well, those modest statements wer…
Q&A With Grey: Favorites Edition
“Challenge: can you post another Q&A within six months?” No. I cannot. “What are your favorite and least favorite kinds of questions to answer?” A long time ago, in a state far away, I did an event with some friends where my job was to pick questio…
Safari Live - Day 340 | National Geographic
This program features live coverage of an African safari and may include animal kills and carcasses. Viewer discretion is advised. A very good afternoon to you all far and wide from the Maasai Mara here in Kenya. We have a lioness over there. My name’s L…
Illegal Marijuana Farms Endanger Wildlife on California’s Public Lands | National Geographic
So two teams coming off separate points on the ridge, press out with it. Okay, right where we’re at right now is what would be considered the lion’s den of marijuana cultivation in California or North America. This is also a prime area for a lot of threa…
The 5 BEST Credit Cards For Beginners In 2024
What’s up, Graham? It’s Guys here. So here’s the deal: over the last 10 years, I have spent hundreds of hours researching how to maximize the value of every dollar that I spend to the point where now I could travel pretty much anywhere I want to in the wo…
Apollo: Missions to the Moon – Trailer | National Geographic
[music playing] INTERVIEWER 1: Would you like to live on the moon? WOMAN: Yes, I would. INTERVIEWER 1: You would? You’d like to be one of the first people to go? WOMAN: Yes. MAN 1: We have one of the most challenging assignments that has ever been gi…