Help me understand Perl.
December 8, 2003 6:47 PM Subscribe
What exactly is Perl? I've recently acquired a domain and am interested in server-side programming. The problem is that I have no experience and it's difficult as hell to find a reliable resource for beginners (minus any quick scripts). Any help would be most appreciated.
Perl is a language popularly used on webservers for server-side applications. O'Reilly makes great beginner books on any language. Here's Perl.
posted by eyeballkid at 6:57 PM on December 8, 2003
posted by eyeballkid at 6:57 PM on December 8, 2003
If your server supports it, you might also try PHP. It's very easy to use and is specifically designed as a web scripting language (whereas Perl's use on the web is more an artifact of it being a good scripting language than being designed for the web).
posted by j.edwards at 7:00 PM on December 8, 2003
posted by j.edwards at 7:00 PM on December 8, 2003
I honestly think PHP would be a better first language than Perl.
PHP is actually based on Perl (at one point in it's history, anyway), and the syntax is very similar. However, PHP is 100% designed for the web, while Perl is designed to do Lots of Things. As such, there tends to be a lot more help for newbies with PHP (in fact, the PHP manual on php.net is one of the best resources around). A quick google search will turn up a slew of decent intro articules on PHP.
I do like writing Perl (although I haven't used it for a web site in several years), but the community tends to be more of a "RTFM" lot.
http://www.php.net/ is a good place to start.
posted by malphigian at 7:05 PM on December 8, 2003
PHP is actually based on Perl (at one point in it's history, anyway), and the syntax is very similar. However, PHP is 100% designed for the web, while Perl is designed to do Lots of Things. As such, there tends to be a lot more help for newbies with PHP (in fact, the PHP manual on php.net is one of the best resources around). A quick google search will turn up a slew of decent intro articules on PHP.
I do like writing Perl (although I haven't used it for a web site in several years), but the community tends to be more of a "RTFM" lot.
http://www.php.net/ is a good place to start.
posted by malphigian at 7:05 PM on December 8, 2003
FWIW, poopy, I was asking a similar question not long ago when I wanted to prototype (on my own, without any programmers to "cloud" my thinking) a design idea I had that was just at heart just a basic databased application, but the presentation layer was quirky... PHP turned out to be immeasurably easier, if only because it's use is targeted at web presentation - perl is a much more generic text manipulation language. From a pretty good knowledge of HTML and a working knowledge of javascript, I was able to connect PHP and MySQL on Mac OS X in next to no time. I'd suggest trying PHP first; if it's too limiting, then you could move on to perl...
posted by JollyWanker at 7:14 PM on December 8, 2003
posted by JollyWanker at 7:14 PM on December 8, 2003
Listen to malphigian. Jumping into server-side programmingby picking up Perl is asking for pain.
These days Perl is mainly (IMHO) for people who like to learn languages that will let them smirk at newbies, or write unreadable code, or bask in the silly idea that easier=weakness.
Perl kicks ass. About 5 years ago.
Today you want to learn PHP. It will let you get huge amounts of work done early in the learning curve. If you really want to learn something with more "legs" than PHP, Python is a better choice than Perl.
A few downsides: PHP isn't the best tool for stand-alone apps. It's also easy to pick up bad programming practices. And PHP is still a rather new language so it's still in developement. There are some very rare bugs.
posted by y6y6y6 at 7:20 PM on December 8, 2003
These days Perl is mainly (IMHO) for people who like to learn languages that will let them smirk at newbies, or write unreadable code, or bask in the silly idea that easier=weakness.
Perl kicks ass. About 5 years ago.
Today you want to learn PHP. It will let you get huge amounts of work done early in the learning curve. If you really want to learn something with more "legs" than PHP, Python is a better choice than Perl.
A few downsides: PHP isn't the best tool for stand-alone apps. It's also easy to pick up bad programming practices. And PHP is still a rather new language so it's still in developement. There are some very rare bugs.
posted by y6y6y6 at 7:20 PM on December 8, 2003
Response by poster: thanks all. from the little bit i've read, PHP was usually mentioned, but being overwhelmed I didn't see the forest for the trees i guess. i'm assuming that PHP can be used to write CGI scripts or am i completely off base?
posted by poopy at 7:23 PM on December 8, 2003
posted by poopy at 7:23 PM on December 8, 2003
Well, php embeds the code directly on your pages, rather than having it run in a seperate cgi file, but you are getting closer.
posted by Hackworth at 7:27 PM on December 8, 2003
posted by Hackworth at 7:27 PM on December 8, 2003
I guess I should add - One of the best things about PHP is that the best documentation is the free docs at php.net.
If you want a place to jump in quick, the tutorials Dev Shed are still my favorite.
And if you want to use PHP with a MySQL database (and you do) phpMyAdmin is your best friend. Most web hosts who offer PHP will also have MySQL and phpMyAdmin installed as well.
posted by y6y6y6 at 7:29 PM on December 8, 2003
If you want a place to jump in quick, the tutorials Dev Shed are still my favorite.
And if you want to use PHP with a MySQL database (and you do) phpMyAdmin is your best friend. Most web hosts who offer PHP will also have MySQL and phpMyAdmin installed as well.
posted by y6y6y6 at 7:29 PM on December 8, 2003
"PHP can be used to write CGI scripts or am i completely off base?"
CGI and server-side programming are different animals. The end result is the same for your purposes, but you'll be better off forgetting about CGI and just thinking about server-side programming. Otherwise it can get confusing since sometimes PHP will run as a CGI, even though PHP is a server-side language, which isn't CGI.
See? It's confusing. Best to pretend it doesn't exist. If the distinction is really ever important you'll be straying into network engineering or sys admin territory.
You can use PHP to dynamically create webpages (like metaFilter does with ColdFusion), do real work on the server/file system, create graphics on the fly, manipulate databases, handle forms, talk to other programs, etc.
posted by y6y6y6 at 7:39 PM on December 8, 2003
CGI and server-side programming are different animals. The end result is the same for your purposes, but you'll be better off forgetting about CGI and just thinking about server-side programming. Otherwise it can get confusing since sometimes PHP will run as a CGI, even though PHP is a server-side language, which isn't CGI.
See? It's confusing. Best to pretend it doesn't exist. If the distinction is really ever important you'll be straying into network engineering or sys admin territory.
You can use PHP to dynamically create webpages (like metaFilter does with ColdFusion), do real work on the server/file system, create graphics on the fly, manipulate databases, handle forms, talk to other programs, etc.
posted by y6y6y6 at 7:39 PM on December 8, 2003
Response by poster: fuck, i guess i gotta lotta work to do. time to hit the o'reilly books :) but at least i know where to focus! i know it might seem like a lazy post but i was thoroughly confused. thanks again.
and matt, if Ask MetaFilter is geared towards more techie questions, you might want to consider some kind of 'level of expertise' categories (i.e. novice--advanced). this might alleviate some potential problems.
posted by poopy at 8:02 PM on December 8, 2003
and matt, if Ask MetaFilter is geared towards more techie questions, you might want to consider some kind of 'level of expertise' categories (i.e. novice--advanced). this might alleviate some potential problems.
posted by poopy at 8:02 PM on December 8, 2003
I've found Core PHP Programming (third edition) to be an invaluable resource for PHP programming, and also probably a good introduction.
posted by j.edwards at 8:18 PM on December 8, 2003
posted by j.edwards at 8:18 PM on December 8, 2003
"i guess i gotta lotta work to do."
It's easier than you'd think. And you don't need a book. Seriously. Start with the docs at php.net.
Try this - Write a script to list out the posters for each FFP at Metafilter.
1) Grab the file (hint: use the file() function)
2) Loop through the file looking for lines that have a "posted by" (hint: use the strpos() function)
3) Pull out the user name from the line (hint: use the substr() function)
4) echo it to the browser. (hint: use echo)
Boom. You have a working app that you could extend to make a reformatted version of MetaFilter. And working through that stuff will give you a good introduction to conditional syntax and control structures.
posted by y6y6y6 at 8:25 PM on December 8, 2003
It's easier than you'd think. And you don't need a book. Seriously. Start with the docs at php.net.
Try this - Write a script to list out the posters for each FFP at Metafilter.
1) Grab the file (hint: use the file() function)
2) Loop through the file looking for lines that have a "posted by" (hint: use the strpos() function)
3) Pull out the user name from the line (hint: use the substr() function)
4) echo it to the browser. (hint: use echo)
Boom. You have a working app that you could extend to make a reformatted version of MetaFilter. And working through that stuff will give you a good introduction to conditional syntax and control structures.
posted by y6y6y6 at 8:25 PM on December 8, 2003
"list out the posters for each FFP at Metafilter"
Yikes. Let me clarify. Just grab the frontpage. Please don't loop through every post from the begining of time in order.
posted by y6y6y6 at 8:33 PM on December 8, 2003
Yikes. Let me clarify. Just grab the frontpage. Please don't loop through every post from the begining of time in order.
posted by y6y6y6 at 8:33 PM on December 8, 2003
Yikes. Let me clarify. Just grab the frontpage. Please don't loop through every post from the begining of time in order.
Shit! Too late! Damnit y6^3! ;)
posted by eyeballkid at 8:39 PM on December 8, 2003
Shit! Too late! Damnit y6^3! ;)
posted by eyeballkid at 8:39 PM on December 8, 2003
Yeah, learning it is easy. You can start small, with just includes and form variables and then work up to the big stuff. The only book I ever read about it was the chapter in O'Reilly's Webmaster in a Nutshell, everything else was learning from example. and the great thing about the web is the abundance of examples. I found that downloading various open source programs around the web and picking them apart taught me faster than a book, but that's just me. Hell, just setting up the Phorum for the original askMetafilter taught me some new tricks.
posted by Hackworth at 9:23 PM on December 8, 2003
posted by Hackworth at 9:23 PM on December 8, 2003
I use Perl, a lot. If you want to generate web pages, you could do a whole lot worse. It's a little sad that it's been pigeonholed as a CGI language, because it can do so much more. If you're not really interested in learning programming, something like PHP might be better for you. If you enjoy learning a language that will give you a lot of power at the expense of figuring out some potentially arcane syntax, Perl is your ticket. It can be daunting to a beginner, but a little bit of perseverance and a good dose of common sense will allow you to write beautiful, efficient, and maintainable code with Perl. If you just want to make the webernets go, though, maybe it's not for you.
posted by majcher at 9:28 PM on December 8, 2003
posted by majcher at 9:28 PM on December 8, 2003
a script to list out the posters for each FFP at Metafilter
So, could I use something like this to (finally) update the Mefi Taglines page? Or would it only work on an already generated page? If it can search the database, is it possible to make it send x requests every hour or something similar to minimize the impact on the database?
posted by dg at 9:32 PM on December 8, 2003
So, could I use something like this to (finally) update the Mefi Taglines page? Or would it only work on an already generated page? If it can search the database, is it possible to make it send x requests every hour or something similar to minimize the impact on the database?
posted by dg at 9:32 PM on December 8, 2003
since it won't be logged in, the program will fetch the static page which is generated every 5 minutes, i think. the database cannot be searched remotely fur as i no.
posted by quonsar at 10:53 PM on December 8, 2003
posted by quonsar at 10:53 PM on December 8, 2003
Perl = executable line noise. (Although kids today probably don't even know what line noise looks like.)
posted by kindall at 12:43 AM on December 9, 2003
posted by kindall at 12:43 AM on December 9, 2003
You might also consider Zope and, particularly, Plone (which is something that runs on top of Zope and makes it easy to start generating your own pages without much knowledge of programming).
Unfortunately, these aren't as widely supported as PHP, so whoever provides your server might not have them installed. If they do, you could give Plone a quick try-out. Basic use is very intuitive (no programming, just clicking on web pages).
Since I've not used PHP, I can't comment on how it compares, but Zope/Plone use Python which is a "nicer" language than Perl (as someone commented above).
posted by andrew cooke at 4:27 AM on December 9, 2003
Unfortunately, these aren't as widely supported as PHP, so whoever provides your server might not have them installed. If they do, you could give Plone a quick try-out. Basic use is very intuitive (no programming, just clicking on web pages).
Since I've not used PHP, I can't comment on how it compares, but Zope/Plone use Python which is a "nicer" language than Perl (as someone commented above).
posted by andrew cooke at 4:27 AM on December 9, 2003
"the database cannot be searched remotely fur as i no."
Well, now we're onto a new question.
True, PHP (or any other language) won't let you make requests directly to the MetaFilter database.
So the solution would be recreate the MeteFilter database locally. I started to do this a while back, but then Matt mentioned the database was using about half a gig of storage and I decided I didn't want to host that.
But recreating the database isn't too hard. I wrote a script that would request an FFP by number every minute. Then I'd parse out the elements - post, comments, times, users - and then just build the tables. Piece if cake. One caviat of course is that you have to find a way to throttle your script so that it doesn't just make requests non-stop. Doing that would bring MeFi to a crawl, and is probably an illegal DOS attack.
The interest for this is that you could do some very cool reporting or customized views. I've done something like this with the killfile page and the news filter page. But on a much more limited scale.
The leason here is that PHP is very good for grabbing files via http and parsing strings. Thus it's also the tool of choice for many people who build spiders and web bots.
posted by y6y6y6 at 5:07 AM on December 9, 2003
Well, now we're onto a new question.
True, PHP (or any other language) won't let you make requests directly to the MetaFilter database.
So the solution would be recreate the MeteFilter database locally. I started to do this a while back, but then Matt mentioned the database was using about half a gig of storage and I decided I didn't want to host that.
But recreating the database isn't too hard. I wrote a script that would request an FFP by number every minute. Then I'd parse out the elements - post, comments, times, users - and then just build the tables. Piece if cake. One caviat of course is that you have to find a way to throttle your script so that it doesn't just make requests non-stop. Doing that would bring MeFi to a crawl, and is probably an illegal DOS attack.
The interest for this is that you could do some very cool reporting or customized views. I've done something like this with the killfile page and the news filter page. But on a much more limited scale.
The leason here is that PHP is very good for grabbing files via http and parsing strings. Thus it's also the tool of choice for many people who build spiders and web bots.
posted by y6y6y6 at 5:07 AM on December 9, 2003
Like others, I wouldn't suggest a non-programmer beginner start with Perl, unless you're brave or feel like a challenge. I'll also give a thumbs up to Python. It's a very versatile language, it can be a simple or as complex as you need, it can do anything Perl can, is quicker to program with once you're up to speed, and if you get into it, you'll find it has many uses beyond web applications. Another nice thing about Python is that there are scripting environments for almost any platform for it, which makes migrating code between platforms, if not entirely painless, a lot less grief than it might otherwise be.
More generally, it's difficult to find objective assesments of the various competing server-side web technologies, because people tend to promote what they know, and very few people are highly proficient with them all. My main server-side skills are with ASP 3, which I've found to be capable for what I need, but I'm the first to agree that VBScript is a pile of poo as far as languages go. However, ASP.NET with C#, which I'm now toying with, is a very impressive tool - a truly object oriented language with a framework library the likes of which was previously only available to those who were willing to wrestle a J2EE server, and much easier employment of compiled objects at runtime.
posted by normy at 8:27 AM on December 9, 2003
More generally, it's difficult to find objective assesments of the various competing server-side web technologies, because people tend to promote what they know, and very few people are highly proficient with them all. My main server-side skills are with ASP 3, which I've found to be capable for what I need, but I'm the first to agree that VBScript is a pile of poo as far as languages go. However, ASP.NET with C#, which I'm now toying with, is a very impressive tool - a truly object oriented language with a framework library the likes of which was previously only available to those who were willing to wrestle a J2EE server, and much easier employment of compiled objects at runtime.
posted by normy at 8:27 AM on December 9, 2003
But recreating the database isn't too hard. I wrote a script that would request an FFP by number every minute. Then I'd parse out the elements - post, comments, times, users - and then just build the tables. Piece if cake. One caveat of course is that you have to find a way to throttle your script so that it doesn't just make requests non-stop. Doing that would bring MeFi to a crawl, and is probably an illegal DOS attack.
The problem with this is, you'd be sucking down tons of unimportant information, such as graphics, css formatting and form fields, that you wouldn't need. This isn't a big deal if you're parsing one page a day, but you're wasting a ton of resources if you're trying to build an archive.
It would be much easier, but more of a burden on Matt, to just write a Metafilter API that connects to the database, either over SOAP or XML-RPC. If you just got the plain text that would eliminate 60-70% of the size of the downloads, I bet.
Also, if you're a non-programmer, stay the hell away from Perl. It's only going to confuse you. I had to get through college software engineering courses before perl started to make a modicum of sense to me.
posted by SweetJesus at 11:41 AM on December 9, 2003
The problem with this is, you'd be sucking down tons of unimportant information, such as graphics, css formatting and form fields, that you wouldn't need. This isn't a big deal if you're parsing one page a day, but you're wasting a ton of resources if you're trying to build an archive.
It would be much easier, but more of a burden on Matt, to just write a Metafilter API that connects to the database, either over SOAP or XML-RPC. If you just got the plain text that would eliminate 60-70% of the size of the downloads, I bet.
Also, if you're a non-programmer, stay the hell away from Perl. It's only going to confuse you. I had to get through college software engineering courses before perl started to make a modicum of sense to me.
posted by SweetJesus at 11:41 AM on December 9, 2003
These days Perl is mainly (IMHO) for people who like to learn languages that will let them smirk at newbies, or write unreadable code, or bask in the silly idea that easier=weakness. Perl kicks ass. About 5 years ago.
What a great demonstration of nonsensical flamebaiting and FUD. Disregard the above please.
Some tidbits to put it straight: Amazon uses Perl and Mason and is actively recruiting new Perl programmers, so they won't be jumping ship soon. Perl 6 is shaping up to be the fastest language in its class, mostly thanks to the sterling work on the Parrot virtual machine. mod_perl is level with, or even beats, bytecode-cached PHP in benchmarks. And well written Perl is extremely readable. More so than PHP, at least. Perl has one of the largest programmer communities, and one of the biggest selections of add-ins and modules offered to any language (see CPAN). Even PHP coders try to steal Perl modules, and languages like Python and C# don't come close.
Most of these Perl haters are either jealous MS aberrees, PHP coders who think 3 years' experience is 'a lot', or coders who consider their language to be more trendy (Python, Java, Ruby).
posted by wackybrit at 12:57 PM on December 9, 2003
What a great demonstration of nonsensical flamebaiting and FUD. Disregard the above please.
Some tidbits to put it straight: Amazon uses Perl and Mason and is actively recruiting new Perl programmers, so they won't be jumping ship soon. Perl 6 is shaping up to be the fastest language in its class, mostly thanks to the sterling work on the Parrot virtual machine. mod_perl is level with, or even beats, bytecode-cached PHP in benchmarks. And well written Perl is extremely readable. More so than PHP, at least. Perl has one of the largest programmer communities, and one of the biggest selections of add-ins and modules offered to any language (see CPAN). Even PHP coders try to steal Perl modules, and languages like Python and C# don't come close.
Most of these Perl haters are either jealous MS aberrees, PHP coders who think 3 years' experience is 'a lot', or coders who consider their language to be more trendy (Python, Java, Ruby).
posted by wackybrit at 12:57 PM on December 9, 2003
And for your script suggestion, no need to do all of that strpos jazz in Perl, of course ;-) Okay, I know I'm being defensive, but making up quick hacks to do quick things is Perl's forté. This will work:
Course, you should use HTML::TokeParser and do it properly instead of using regexes to parse HTML but that works as a temporary hack. Besides, LWP::Simple = eugh. In fact, if you have Perl installed on your machine, this should work from the command line:
posted by wackybrit at 1:19 PM on December 9, 2003
use LWP::Simple;
$_ = get('http://www.metafilter.com/');
print join '\n', (/posted by <.*?>(.*?)</ig);
Course, you should use HTML::TokeParser and do it properly instead of using regexes to parse HTML but that works as a temporary hack. Besides, LWP::Simple = eugh. In fact, if you have Perl installed on your machine, this should work from the command line:
perl -e "use LWP::Simple; $_ = get('http://www.metafilter.com/'); print join \"\n\", (/posted by <.*?>(.*?)</ig);"
posted by wackybrit at 1:19 PM on December 9, 2003
Response by poster: wow, thanks everyone (especially y6). after attempting a few simple scripts i've found that this is exactly what i'm looking for. perl looks like an extremely robust language but i don't need anything like that, just some simple processing of forms really and PHP fits like a glove.
posted by poopy at 4:51 PM on December 9, 2003
posted by poopy at 4:51 PM on December 9, 2003
This thread is closed to new comments.
posted by timeistight at 6:51 PM on December 8, 2003 [1 favorite]