views:

447

answers:

9

Update:
Thank you all for chiming in. It's tough to pick a winner, so I went with the highest voted with the most information. I'll check out perlmonks and I'll look into some of the books mentioned as well.
End Update

Let's say I'm looking for help with Perl. (I am. I'm just getting into it.)

Compared to PHP, I'm really disappointed by the quality of Perl-community tutorials and code examples / documentation.

I google: "Perl list files in directory" and just about everything I come across is bad advice, vague, poorly documented quick snippets, or just doesn't work.

http://perldoc.perl.org/ has really lame examples and almost no code comments or explanations of functions.

http://us2.php.net, on the other hand is really amazingly documented, clear, fleshed out, and makes sense to anyone just coming into contact with the language (or new function/feature of the language).

For example, compare these two pages for reading files in a directory.

PHP vs. Perl

Where can I find the best, most reliable set of examples of Perl code?

+5  A: 

CPAN?

dsm
Better: http://search.cpan.org/
Chris Dolan
+3  A: 

Try reading Programming Perl or Learning Perl.

Rob K
Programming Perl by Larry Wall is an awesome book. It's hugely thick, but is loaded with great examples and funny jokes.
Ben S
+2  A: 

I have used Perl for many years, and have found that "the Camel book" is really the best resource available for instruction, example code, and language reference.

I believe part of the problem is that Perl is no longer a shiny new language, so its enthusiasts mostly have been using it for a long time already, or are learning it because they have to. Don't get me wrong - it's a fantastically great systems language. But I believe it's being surpassed by other languages such as Python and Ruby (and PHP on the web).

By the way, I looked at the first example for "Perl list files in directory" on google:

opendir(DIR, "yourDIR");
@FILES= readdir(DIR);

This seems correct and concise. Perl's philosophy is TMTOWTDI ("tim toady"): There's more than one way to do it. This idea has become passe to an extent in more 'modern' languages, but this may be why you find 12 different ways to list files in a directory :)

drue
I'd say the example has problems. It does not check for errors. It uses a package global handle. It does not use strict. It uses all capital letters in a variable name. Something like: opendir( my $dh, 'dirhere' ) or die "Ugh: $!"; my @files = readdir($dh); is more appropriate.
daotoad
^ What he said: those examples are not correct or at least not idiomatic, modern Perl.
Telemachus
it also doesn't explain (as daotoad says) the DIR package global handle. ...until I read that here, I wasn't sure what that was - and I've seen numerous examples using that. every one just assumes everyone already knows. that's problematic :)
42
looks like opendir and readdir weren't working for me partly because I'm accessing a dir on a remote computer on our LAN via 1) a shared directory z:\share\path and 2) unc \\share\path. neither work on IIS5
42
my @files = grep { -f } </path/to/files/*>;
JDrago
+11  A: 

PerlMonks is a good community to turn to for help and examples.

Ben S
+6  A: 

Sometimes the web isn't always the best repository of knowledge for some folks learning a new language (myself included). You could buy one of the many excellent titles on Perl such as those published by O'Reilly:

Learning Perl, Fifth Edition - (one of the authors brian d foy is a StackOverflow contributor)

Programming Perl by Larry Wall - Larry invented Perl so what more can you say?

O'Reilly also have a great Perl resource site:

http://oreilly.com/perl/

When I'm learning new tricks I often find that starting with a proper book, made from actual dead trees and ink, structures my learning far better than randomly hopping around 'tutorial' and 'self-help' sites.

HTH
Kev

Kev
+5  A: 

If you want to learn by example then I can't recommended The Perl Cookbook highly enough.

It's nothing but page after page of examples showing you how to achieve various things using Perl.

You can have a read of it online at Google Books.

Dave Webb
+13  A: 

Programming Perl is a great book, but some of the advice is dated.

For a new Perl programmer, I'd recommend in order of importance:

  1. Visit: Perlmonks daily.
  2. Read: Learning Perl.
  3. Have on hand: The Perl Cookbook.
  4. Read: Perl Best Practices
daotoad
+5  A: 

Does it bother anyone else that the OP compares the documentation for PHP's readdir to Perl's File::Find?

  • The comparison should be PHP's readdir versus Perl's readdir, no?
  • Beyond that, File::Find itself (which I have come to love despite myself) has a notoriously unfriendly and clumsly style. (Ie, maybe the docs for that module aren't the best single example for anything.)

Maybe I'm an uncritical Perl fan, but I've always found Perl's documentation and http://perldoc.perl.org/ to be remarkably good. The docs aren't simply a bunch of examples thrown together. They teach you how to program using Perl. They treat you like an intelligent adult. Imagine that.

Telemachus
You're welcome. (I point out a bad link and all I get is this lousy downvote...)
Telemachus
for the record, it wasn't me, even though I did consider it :)
42
No worries. You can't take it personally.
Telemachus
Years ago when I was looking for a programming language to handle some web stuff, and maybe a little automation on the side, I looked at PHP and Perl. I was impressed by PHPs docs, and the comments were very nice. Perl's docs seemed cryptic. I eventually got used to the perldocs.
daotoad
daotoad
File::Find makes more sense to those who understand map and grep.
JDrago
+2  A: 

Go to php.net and type "list files in directory" into the search box (top-right). You get zero results.

http://us2.php.net/manual-lookup.php?pattern=list+files+in+directory

Go to perlmonks.org and type "list files in directory" into the search box (top-left). You get some answers: http://www.perlmonks.org/?node=list+files+in+directory

JDrago