perlsyn - sed syntax?

schwern on 2003-05-14T06:52:45

Reading the first two paragraphs of perlsyn, I've noticed there is more information in there about sed, awk, C and command line switches than introductory perl syntax.

A Perl script consists of a sequence of declarations and statements. The sequence of statements is executed just once, unlike in sed and awk scripts, where the sequence of statements is executed for each input line. While this means that you must explicitly loop over the lines of your input file (or files), it also means you have much more control over which files and which lines you look at. (Actually, I'm lying--it is possible to do an implicit loop with either the -n or -p switch. It's just not the mandatory default like it is in sed and awk.)

Perl is, for the most part, a free-form language. (The only exception to this is format declarations, for obvious reasons.) Text from a "#" character until the end of the line is a comment, and is ignored. If you attempt to use /* */ C-style comments, it will be interpreted either as division or pattern matching, depending on the context, and C++ // comments just look like a null regular expression or defined-or operator, so don't do that.

What is this actually teaching?

  • A Perl script consists of declarations and statements executed once no matter what the input.
  • Sed and awk execute once for every line of input.
  • Perl has -n and -p switches to act more like sed and awk
  • Perl comments start with #
  • C comments look like /* */
  • C++ comments look like //
  • // is either a division or null regular expression or defined-or in Perl


This quantifies like so:

  • 2 facts about basic Perl syntax
  • 2 facts about advanced Perl features
  • 3 facts about other languages/tools


Obviously a hold over from the days when Perl was just a replacement for awk and sed and Real Programmers coded in C. While this information might be useful, the opening paragraphs of the Perl syntax documentation is not the place to put it.


separate pods ?

WebDragon on 2003-05-14T13:17:56

I for one would like to see a separate pod file dealing specifically with sed, awk, etc. Possibly either detailing the differences between perl and these, or detailing how to convert bits of sed and awk into pure perl..

Yes it's in there now, but moving them off to their own section would allow a little more expounding on these topics, and may remove some of the clutter from those pods that contain these references now.

If this makes no sense, it's because I'm still on my first cup of coffee.. ;-)

Reorganize rather than re-write

VSarkiss on 2003-05-14T15:20:02

It's useful information, but you're right, it doesn't belong in an introductory document. It might be more appropriate in perltrap, for instance.

In the same vein, I keep thinking there's a lot of documentation, but it's hard to skim because it's all one flat structure. (How many people remember what's in perldsc?) It would be nice to have it arranged into groups, maybe something like:

  • Introductory and Core: perlsyn, perlfunc, perldata, perlbook, perlboot, etc.
  • Internals: perlguts, perlhack, perldebguts, etc.
  • FAQs: perlfaq1 thru N
  • System-specific: perlaix, perlhpux, and all the rest.
  • Tutorials: perldsc, perltoot, perltooc, perlretut, etc.
I could go on, but you get the idea. It would be even better if you could cross-reference, since some things easily fit in more than one category.

I'd gladly make and maintain such a list, but I don't know how to get it out there. Give it to you? ;-)

Re:Reorganize rather than re-write

schwern on 2003-05-14T22:58:56

5.8.0's perl(1) already does that breakdown, pretty much exactly along those lines.

As an aside, the formatting on perldoc.com is quite nice.