Forum: Geek Forum Topic: Who wants to learn Perl? started by: damien_s_lucifer Posted by damien_s_lucifer on Oct. 29 2001,01:34
I'm having a grand ol' time helping someone learn C via email. It's good exercise for me. I use Perl so much that my basic C skills are kind of rusty, and this forces me to polish them up.It's also making me remember why I fell in love with Perl in the first place. So here's an offer to those of you who know C, and are interested in checking out Perl, but don't want to blow fifty bucks on the Camel Book (Programming Perl by Larry Wall et. al, O'Reilly Press) without knowing if you're even going to USE Perl. If there is sufficient interest I'll teach a mini-course on the language. Things you'll need : - a working knowledge of C or C++. You don't have to be a C guru, but you should understand the basic control structures (if, for, while, etc.) - A working copy of the perl interpreter, v.5.04 or better. If you're running Linux, you probably already have one - type 'perl --version' at the shell to see what version you have. Windows users can download it from < ActiveState >; it's freeware. - A text editor. Windows users can use Notepad, but I highly recommend < TextPad > so you can have syntax highlighting. - If you want to write CGI scripts, you'll need to have access to a Web server that is configured to support them. I can help a bit with Apache; IIS users are on their own unless someone who knows IIS wants to help out... If you're interested, let me know. Posted by LiNeY on Oct. 29 2001,14:52
ME ME ME!!! I'd love to learn Perl, but being that I'm the someone just being taught C via email... I guess I'd better wait a while. But I already want to say that after C you gotta teach me Perl. ------------------ Posted by demonk on Oct. 29 2001,15:42
Perl kicks some major ass! It's what Java has always wanted to be but failed at (it can run on almost ANY OS with little to no modification to the code). Plus it's the only OO scripting language I know of And doing GUI is sooooooooo easy with Perl/Tk! And I know for a fact that it is the scripting language standard at places like Intel, so there definatly are real world benifits to learns Perl. I've been playing with Perl in my spare time and using at work (Intel), and I'm ALWAYS learning new tricks with it. You won't regret learning it.------------------ Posted by damien_s_lucifer on Oct. 29 2001,19:00
quote: your post, demonk, is dead-on. I keep hearing that Java is the standard, everyone should use Java, blah blah blah. Java gets a lot more press, but if you look under the hood of most websites, you're a LOT more likely to find Perl than Java Servlets or some other technology du jour. Look back through history, and you'll find that there have been hundreds of languages that were sure to be the next Big Thing... but it's the ones that spread quietly that stuck around. Right now all the k1dd1es are rushing to learn Java and Visual Basic. Unlike C or Perl, the languages don't make you spend years mastering the intricacies of good code to write something cool. But they also limit you in ways that Perl and C don't... so if you want to grow, you have to go learn Perl and C anyway, but by that time you're so used to the *GET*RESULTS*NOW* style of coding that Perl and C just seem frustrating and boring and you give up. I've seen it happen plenty of times LiNey, sure, I'll teach you Perl... but let's get thru the basics of C first. Learning C forces you to learn the Rules of Good Programming that have stood the test of time. Perl doesn't enforce the rules because it assumes you already know them. It allows you to write sloppy code if you want. For beginning programmers, this means it will happily allow you to develop very bad programming habits. For example, C makes you declare all your variables. This makes you keep track of what variable you're using for what purpose. Perl, on the other hand, allows you to pull variable names out of your ass and use them wherever you see fit. Depending on your experience, this can be a blessing or a curse... Posted by kornalldaway on Oct. 29 2001,19:10
question:is it better to start with perl and then move on to c or the other way around? Posted by Spydir on Oct. 29 2001,19:37
C's the base for a lot of languages that have come out since 1970, and if it's not the base it either got some C style stuff. And if it has nothing at all to do with C, it probably sucks.------------------ Posted by chmod on Oct. 29 2001,20:03
quote: no, most definitely start with C first... as dsl noted. Posted by Tattered on Oct. 29 2001,21:27
Any recommendations on sites / books / large pdf files for me to learn C from.. right from the basics.. I had my fun with basic and turbo pascal 7 a couple years ago.. but never caught onto C.. I think it would be really interesting to learn though.. and then maybe I'll take an interest in perl as well.This message has been edited by Tattered on October 30, 2001 at 05:32 PM Posted by damien_s_lucifer on Oct. 29 2001,23:01
Pascal was the first compiled language I learned! I still have good ol' bp.exe and turbo.exe on my hard drive Pascal and C are so similar that you should be able to dive into Perl without a problem. Almost all the differences have to do with syntax : - begin and end in Pascal are written { and } in C Otherwise, the data types are pretty much the same, accessing data is pretty much the same, control structures are almost the same... This message has been edited by damien_s_lucifer on October 30, 2001 at 06:04 PM Posted by Beldurin on Oct. 29 2001,23:04
quote: I seem to recall that it wasn't that difficult (but it was a LONG time ago). I do, however have access to IIS servers to play around with and figure it out if anyone needs the help. I went through a fairly logical progression (I think): Some BASIC (very little) And for the record, I still maintain (in the face of opposition and stupidity) that HTML is not a programming language. Thank you. edit: had to edit ------------------ This message has been edited by Beldurin on October 30, 2001 at 06:07 PM Posted by DeadAnztac on Oct. 29 2001,23:45
I know C++, I know PHP , I know some Java, I know JavaScript, I know all manners of SH's, I know some BASIC (::Shiver: :), but I want to know more PERL, so any help would be cool, mostly for any admining stuff. I admin a few different servers, all with PERL of course.------------------ This message has been edited by DeadAnztac on October 30, 2001 at 06:45 PM Posted by LiNeY on Oct. 30 2001,14:04
quote: Yeah. SAMS Teach Yourself C in 21 Days, by Peter Aitken and Bradley L. Jones. I work with that book and I think it's really good (fifth edition; bestseller on the US market as far as I know). Even I, without being able to tell RAM from Hard Disk in the beginning, checked what C was about. Just one thing: with "in 21 days" they mean "in 21 days, working 24/7". So plan in a bit more time than three weeks. ------------------ Posted by Der_Teufel on Oct. 30 2001,23:23
I'd love to learn Perl. I took a year of C++ in high school and am gonna take a C++ class next semester for CpE. In my high school class the old teacher had left so they brought in a new teacher who had never taught a programming class before. When she got to classes she didn't teach them well, which resulted on a 2 on the AP exam. If I had know classes i could have gotten a 4 or 5 cause of how easy the multiple choice is. I was so pissed when I got the free response section.... ALL OF IT WAS CLASSES!!! Can someone point me in the direction of a good site or book that would clear up classes for me? I wanna get my C++ skills back so I can breeze through this class next semester.
Posted by TonyDennis on Oct. 31 2001,03:45
I want to learn PERL!
Posted by damien_s_lucifer on Oct. 31 2001,04:21
Okay... the first Perl lesson will start sometime next week, when I've recovered from the insane work binge I've been on the last 10 days.Registration is still open, of course. Until then, $damien = s/lucifer//g; Posted by Spydir on Oct. 31 2001,16:49
I guess I'll join in. I got a few perl/cgi books, and I've been tinkering with it for a while, but I need some good exercises and stuff to really learn it.------------------ Posted by DuSTman on Oct. 31 2001,18:26
Hmm. Count me in. I've been thinking about learning some perl and have done the first few lessons of some tutorial, but this tutorial should still prove useful. Thx. Posted by damien_s_lucifer on Oct. 31 2001,22:11
Okay. Here's lesson zero Fire up your text editor, enter the following code, and save it as hello.pl: code: Execute it with perl hello.pl. Not much of a program, I know. But it illustrates some fundamental difference between C and Perl : - There is no compilation step in Perl. Scripts fed to the Perl interpreter run immediately. - Perl is an interpreted language, which means that a Perl program needs to be fed to the Perl interpreter in order to run. If you're using Unix or Windows NT/2000/XP, there are ways that you can make your Perl script executable from the command line... we'll cover this in Lesson 1. - C expects you to have a function called main(). Perl thinks a program starts at the beginning, and ends at the end. Furthermore, Perl doesn't require any sort of "end" or "exit" statement; it knows enough to stop when it runs out of script to execute. - You don't have to #include <stdio.h> or anything silly like that. Basic I/O functions are native in Perl. - Like C, Perl doesn't slap a newline onto the end of every print statement for you. You need to explicitly specify it as . Almost all of the backslash-escapes (like , \e, etc.) used in C are present in Perl. Hope that's enough to whet your appetites a little bit... next week we'll start the Real Lessons. Posted by Spydir on Oct. 31 2001,22:24
or you could add "#!/usr/bin/perl" for the first line (change /usr/bin/perl to whereever you compiled perl) and it's not absolutely required to pump it directly through the interpeter's command.You also forgot to mention the hundreds of ways to do that same thing with perl. That's one of the wonderous things of perl, there's millions of ways to do the same task. ------------------ Posted by porn_dealer on Nov. 01 2001,00:43
I wouldn't exactly say that there's hundreds of (good) ways to print "Hello, world". At least, there's less than ten. But you make a good point, with Perl you can do things so many different ways.------------------ Posted by MattimeoZ80 on Nov. 01 2001,05:47
if theres one reason to learn perl... its becase...REGEXPS ROCK! seriously, they're amazing. of course you can do tons more, but i've used perl in some cases just for the regexps, heh. Posted by Tattered on Nov. 03 2001,02:06
I hope I'm not spoiling next weeks lessons by asking this .. but how do you ask the user to input something, and then save it to a variable.. and then how do you print a variable?
Posted by chmod on Nov. 03 2001,02:56
print "blah blah enter a value: ";$var = <STDIN>; print "$var "; Posted by DeadAnztac on Nov. 03 2001,07:16
Oh, cool, PERL's like PHP, you can use variables inside ""'s. Kick ass!------------------ Posted by Der_Teufel on Nov. 03 2001,19:35
Last night I was in a friend's dorm after plaing some basketball and one of his suitemates is like a beta tester for Mirosoft. This guy is gung-ho for everything Microsoft. I asked him what languages he knew and he said VB, Java, and C/C++. I then asked his opinion on Perl and he said that it was a shitty language and that it would be better to learn VB or Java. This guy is the biggest dick. I've never meet someone who is so gung-ho for Microsoft.
Posted by Spydir on Nov. 03 2001,22:36
You should meet the "computer expert" at my school.------------------ Posted by veistran on Nov. 04 2001,01:50
maybe he just doesn't have a soul?
Posted by semper on Nov. 04 2001,20:57
Perl's a dead useful language, sometimes the syntax is a bit weird. I used to be really good with it, but I've gotten so used to PHP that I barely remember the regex switches.
Posted by Tattered on Nov. 04 2001,23:00
We starting lessons soon? I'm anxious.
Posted by Beldurin on Nov. 04 2001,23:51
quote: Amen to that! edit: bold messed up my quote
This message has been edited by Beldurin on November 05, 2001 at 06:52 PM Posted by damien_s_lucifer on Nov. 05 2001,01:46
soon, people, soon. At the moment I'm dead tired... and in trouble at work once again. This time for "blowing off users," which finally caused me to snap that I wouldn't be so grumpy if I wasn't working 60-70 hours a week... boss didn't like that much Yes, Perl interpolates variables like PHP. And the Perl motto is "There's More Than One Way To Do It." Lesson 0.1 : Reading from Standard Input code: Here's a line-by-line rundown : $input = <>; Unlike most languages, every variable in Perl starts with a punctuation symbol - either $, @, or \%, depending on what type of variable it is. The $ in $input denotes a scalar, which holds a number or a string. Perl's loose typing doesn't draw much of a distinction between the two, choosing instead to numify strings and stringify numbers when necessary. More on this later... those of you who are itching to know may want to try printing out the result of something like ($input*42) The = is your standard assignment operator, which works just like = in C or := in Pascal. <>, called the "spaceship operator", reads a line from a filehandle, or standard input if none is specified. chomp $input; The chomp() function hacks off a newline at the end of a string if there is one. Since you'll presumably be pressing ENTER after you've typed something in, there will be one at the end of $input. If there is no newline at the end of the string, the string is unmodified. If you want a function that chops off the end of a string no matter what, use chop() print "You typed $input.
"; Now for the "There's More Than One Way To Do It" motto - the program we just looked at could just as easily written as $input = <>; i.e. without the chomp(), or the trailing in the print statement. It will work the same either way. Personally, I like to chomp() all my strings as soon as I read them, and then manually add in newlines when I need them - it keeps me from having to worry about what has a newline and what doesn't and what my regexps will match. But that's my way. Your milage may vary. Coming soon - a small program to demonstate most of Perl's really cool features... This message has been edited by damien_s_lucifer on November 05, 2001 at 08:47 PM Posted by askheaves on Nov. 05 2001,02:10
I read halfway into that post, and my eyes glazed over and rolled halfway into the back of my head. I totally got lost when you started showing that Perl is weak-typed. I got scared that it would convert my ints to strings and my strings to doubles. It hurt my head.Maybe I should start a thread for people who want to learn C#. Strong typing! I hate finding my errors in runtime. Ack, mein style ist so geil! Posted by DeadAnztac on Nov. 05 2001,02:14
quote: actually, one would print code:You typed blah blah ladda da. and one would print code:You typed blah blah ladda da Just for the sake of being anal. Sorry. ------------------ Posted by veistran on Nov. 05 2001,02:16
yeah, that is understandably scary.
Posted by Beldurin on Nov. 05 2001,04:04
Weak typing isn't necessarily bad, it depends on what you're doing. The only time it will stringify your ints or intify your strings is if you try to apply an operation of that type, i.e.code: Now, if you want to concatenate them, you would simply: code: voila, $newstring is "12" Now, say you want to add the characters 1 and 2 within those strings (to equal 3), instead of typecasting, you can simply use the addition operator and they're converted for you. code: The interpreter was written to be pretty clever. Remember that you're not writing huge applications with Perl (or PHP), you're only scripting . Weak typing is much quicker to program and IMHO more versatile. Strong typing, while it cuts down on runtime errors, is cumbersome for most scripts. (damn, I think that's my longest post ever!) ------------------ Posted by veistran on Nov. 05 2001,04:50
and it has no edits, yet at least.
Posted by Beldurin on Nov. 05 2001,15:25
quote: I misspoke...I should've said that I have never used it for anything larger than small to medium-sized specialized scripts. I apologize.
quote: Amen. edit: here's one This message has been edited by Beldurin on November 06, 2001 at 10:26 AM Posted by damien_s_lucifer on Nov. 05 2001,17:30
quote: Ah, two common misconceptions. MYTH #1 : Perl is just a scripting language, and not for writing big applications. First, there are plenty of *very* large applications written in Perl. Entire Web management systems run in Perl. Perl has one of the best SQL interfaces around. I've written Perl programs many thousands of lines long, which import tens of thousands of lines in modules... and so on. verdict : bullshit
I've never found that strong typing "saves" anyone from runtime errors. Personally, I think it introduces a hell of a lot more... I have many fond memories of doing a bunch of casting in order to do an end-run around strong typing, and inadvertently casting to the wrong thing and putting too many bytes where they didn't belong. This was especially fun on DOS, where such a bug would usually hang the entire system. I've made plenty of mistakes in Perl, but I don't remember *ever* making a mistake that was even remotely tied to weak typing. Hell, I've never even had a Perl program dump core ("This program has performed an illegal operation and will be shut down" for you Windows users.) verdict : bullshit. Posted by damien_s_lucifer on Nov. 05 2001,18:23
not just M$. Sun is big on strongly-typed languages too.Mostly I think askheaves payed too much attention in CIS courses Posted by Spydir on Nov. 06 2001,05:05
you guys are just forgetting heave's is M$'s bitch...
------------------ Posted by damien_s_lucifer on Nov. 10 2001,21:42
Dear peeps -I have to cancel the Perl lessons. See < this thread > for reasons why. I'm still here to answer any Perl questions you have. If you are really interested in Perl, scrounge up fifty bucks and buy Programming Perl, 3rd edition by Larry Wall et al. It's well worth the money. If you can't afford 50 bucks, you can probably dig up the 2nd edition pretty cheap if you look around. The 2nd edition is still a great book - it's the one I learned Perl from. The 3rd edition has more chapters and info on some more advanced topics. Also, if you find someplace on the Web that SELLS the 2nd edition cheaply, post a link here so others can get it Thanks for all your interest. Makes me feel pretty damn cool. D.S.L. Posted by Spydir on Nov. 12 2001,05:17
I got the book in html format, if anyone wants it. email me if you do.------------------ |