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

Perl Lesson 1 (Summer Programing Course)


4m read
·Nov 3, 2024

Hey guys, this is Mackins and one with a Perl lesson. Now I know I've had Perl lessons before, um, but they weren't that good. And so this is part of the summer agenda programming course. I'm going to be doing Perl. So Perl is our first interpreted programming language, and interpreted means that it doesn't compile into computer code that the computer itself knows how to handle.

Another program on your computer called Perl actually runs this Perl script that you write. So we're going to be using terminal to write our own little Perl programs that will, um, in this lesson, have you enter a number and, um, or how you enter something, you'll say that thing back and something else along with it. So you should watch other terminal lessons before, um, watching these Perl lessons. I think the first maybe five or six terminal lessons would do, but you should really know how to use terminal efficiently before you do these Perl lessons.

So I'm going to see to my desktop and I'm going to VI a program called hello world. And that is the file extension. You can also use Nano to edit a file, but I'm going to use VI, so I'll just hit enter and start editing my Perl program.

So the first line of every Perl program on Unix should be #!/usr/bin/perl. Now I'll hit enter, and now you want to type here. Here's how you, um, print something: print "Hello, what's your name? \n"; And then they'll type their name right there, and you need to end the line with the semicolon.

So now how do we declare a variable that's a string and get text into that string? That's easy, and in fact, declaring a variable, you don't have to do my $variable_name; or my @array_name; or whatever. You can just declare it. So you do $name = <STDIN>; and then a value. So in this case, we're going to do $name = <STDIN>;. And STDIN is all caps.

So this is not only declaring a variable called name; it's assigning it to be <STDIN>, which will read a line from a file. The file STDIN is, um, or STDIN in all caps, is the terminal. So I'm reading a line from the terminal. So whatever they type in, there's no limit to the amount of characters that can be put in this variable, and this variable is not at all a character array or a string or anything. It's just something stored in memory that you can treat as a number, a letter, or anything.

Then, just like when we did that thing with C, it is going to end with a new line. Now there's an easy way with Perl to get rid of that. You just type chomp($name);, and then the variable name. The variable name always starts with either $ or @. The @ sign means it's an array of variables, and $ means it's one variable. We're going to be using $ in all these Perl lessons.

So now I'll go to the next line and I'll say print "Hello, $name.\n"; So in the middle of a piece of text, you can put $name, or the dollar sign and then the variable name, and instead of printing $name, it'll print the contents of the variable.

So say we want to print something that has a dollar sign. So I'll say, "You're worth $10." Okay, so, um, say you want to make this dollar sign 10 a piece of text. Whenever there's a dollar sign, you just put a backlash before, and that makes it print out a dollar sign, not look for a variable name. So I'm putting out their name, and I'm saying they're worth $10.

So now I will run this. So the way to run any Perl program is you type perl space and then the name of the program. And normally, that's a path to the program, so you can just type perl space and then drag in the script.

And now it says, "What's my name?" I'll say, "Alex." "Hello Alex, you're worth $10." So that is how to write a hello world program. You can also rename it to something that doesn't have, um, what's it called, a .pl extension, so it's just a text file. It'll open up with TextEdit then, and you'll be able to edit it more.

And if you want to make it executable, you can do chmod +x space and then drag in the script, and then it'll automatically open the terminal. So if you've watched our other terminal lessons, it should be a snap for you. You should get it. You should be able to use Nano to edit the file, and then you should be able to type the code.

So this is how to use Perl to write any program. So, um, hopefully, you've understood this. If there's anything not clear, which I totally understand, please comment and or personal message me and ask me the question you have because I go very quickly in these lessons since YouTube has a time limit on their videos.

So thanks for watching and goodbye!

More Articles

View All
TRACTOR PULLS: It's Not What You Think - Smarter Every Day 276
This is an absolutely preposterous tractor and it’s pulling [Music]. Something; all these people are in these stands to watch what’s called a tractor pull because it’s awesome. The winner is whoever pulls this sled the farthest before getting bogged down …
One Final Shot: 15 Opportunities That Are Going Away Soon
You have all the time in the world until your world suddenly doesn’t have much time left. This year might be your last chance, so here are 15 things you’ve got one last chance to do. First up, change career fields. We seem to be at a breaking point here.…
5 Minute Teaser - Jordan Peterson Responds to Channel 4 Interview Controversy
Then the memes came and then a day later kind of took a joyless turn. Yeah, yesterday and today, right now. Yeah, well, it’s amazing. Well, so here’s the strange thing. Hey, so I kind of played, let’s say, knight on white horse. The Guardian yesterday pu…
Australia's John Anderson & Dr. Jordan B Peterson: In Conversation
[Music] [Music] [Music] Well, Dr. Jordan Peterson, welcome to Sydney on your Australian tour. You’re talking to packed out houses and the interest is extraordinary. We’ve had the opportunity to talk personally, and I can understand why. I want to begin …
Will a ROCKET POWERED SAW cut wood? - Smarter Every Day 210
You wanna see it kicking back in normal conditions, and you wanna test it in not-so-normal conditions. Until that’s not kickback, you wanna give it all of the edge cases so it knows what’s going on. [Destin] Why are you smiling, why are you smiling? (lau…
Adapting when doing business with different cultures!
The old days when 80 percent of the Jets were owned by U.S corporations and 19 of the worldwide jet ownership was in Europe, it was one percent all around the rest of the world. Most of the people in the U.S or in Europe are used to Western ways of doing …