Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Comment on

by blazar (Canon)
on Oct 03, 2007 at 23:41 UTC ( #642535=perlmeditation: print w/replies, xml ) Need Help??

At the request of Lady_Aleena I'm duplicating here some comments to excerpts from a site she had been somewhat naively "advertising". (In the original they've now been put in spoiler tags.) Perhaps someone may want to add further comments, since my reply was buried deep enough in the original thread not to have much visibility.

This tutorial will be covering the PERL syntax and should provide you with a very solid foundation of PERL for you to build upon.

There's Perl and there's perl, but not such a thing as PERL. This is even the subject of a faq entry. Please notice that this may seem a very lightweight flaw to you but as you can read e.g. in PERL as shibboleth and the Perl community it is much used in Perl circles to tell who's in the know from who is not, and it's not a matter of elitist attitude, trust me: whoever wrote that doesn't know Perl but in possibly a very superficial manner and I wouldn't want read on the site, but let's go on...

The language is very simplistic, offering optimum flexibility, perfect for short, straightforward scripting.

I can't see how one could claim Perl to be simplistic: it is often alleged to be awkwardly complex instead...

First things first, you must have PERL 5.005 installed on your web hosting machine. Version 5.005 is available for download via, just follow the download links.

It's dealing with 5.005 and while Perl is mostly backwards compatible, this detail clearly shows that the tutorial is at best seriously outdated.

Regardless of the program you choose to use, a PERL file must be saved with a .pl (.PL) file extension in order to be recognized as a functioning PERL script.

Where? Why? How so? Funnily enough the "tutorial" is strongly geared at *NIX audience, where the concept of "extension" is even non-existant. And as far as the web server is concerned, it's all up to its configuration, but that claim with "must" is plainly wrong and misleading.

File names can contain numbers, symbols, and letters but must not contain a space. Use an underscore (_) in places of spaces.

Where? Why? How so? While I don't particularly like spaces in filenames, especially in programs, most modern enough osen can happily deal with them, from *NIX where anything but "\0" and "/" can be used, to Win where they're actually abused. So what?
#!/usr/bin/perl print "content-type: text/html \n\n"; print "Hello, PERL!";

Personally, however web-oriented the tutorial may be, I would introduce

use strict; use warnings; use CGI;

and -T early. Good programming practices are good programming practices everywhere, even more where security matters...

Another great debugging technique is to isolate the code you are currently working on. To do this you can temporarily comment out lines of code to isolate only the section that is returning an error message.


Comments are necessary for any script you wish to publish to others or make readily available.

Not necessarily. Well crafted, self explaining code with proper POD documentation could happily have very few to no comments at all.

#!/usr/bin/perl print "Content-type: text/html \n\n"; # the header ######################################### #Comments start with a # #########################################

Whoa! What a nice practice to advertise...

In PERL we use the backslash (\) character to escape any type of character that might interfere with our code. For example there may become a time when you would like to print a dollar sign rather than use one to define a variable. To do this you must "escape" the character using a backslash (\).

Not in "PERL". In double quoted strings. Because he should say, first, that those strings interpolate variables. Outside of a string, the backslash befor a dollar sign has an entirely different meaning.

The latter example using the my parameter is another means to define a variable that you might run across as you gain more experience. It is not necessary to use the my parameter. Variables can be defined either way.

Funny: I had never heard anyone call my a "parameter"! Anyway, he who writes shows not to have understood what it is all about and if by any chance he/she did, then he's still giving that impression.

Scalar variables are simple variables containing only one element--a string or a number. Strings may contain any symbol, letter, or number.

No, they can contain much more.

Notice that we used a period (.) between each of our variables. This is a special kind of operator that temporarily appends one string to another.

"Temporarily"? Also, the IMHO bad example with print will get some people into the habit of always using the concatenation operator.

Numbers are scalar data. They exist in PERL as real numbers, float, integers, exponents, octal, and hexidecimal numbers.

Not exactly: some confusion between ways to specify numbers, and numbers.

Logical operators state and/or relationships. Meaning, you can take two variables and test an either or conditional. Logical operators are used later on in conditionals and loops. For now, just be able to recognize them in the upcoming examples.

Funnily enough, he mentions numeric and stringwise comparison operators at a time, in a table, without specifying in what they differ and thus giving the impression that e.g. > and ge are equivalent. To be sure, it claims that 7 ge 11 is a false value. But it is true!!!

C:\temp>perl -le "print 7 ge 11" 1
There are two ways to set an array to scalar mode. We can use the scalar() function or we can redefine the array as a scalar variable.


Ok, I grew tired and I'm stopping here, but I'm sure there are quite a lot of other "gems"...

Replies are listed 'Best First'.
Re: Comment on
by graff (Chancellor) on Oct 04, 2007 at 01:41 UTC
    Indeed, that "tutorial" is beyond bad. You gave up -- quite understandably -- before noting this gem (in a section called "PERL - Define A Hash"):
    print "Content-type: text/html \n\n"; #HTTP HEADER #DEFINE SOME ARRAYS %coins = ("Quarter", 25, "Dime", 10, "Nickle", 5); %ages = ("Jerry", 45, "Tom", 22, "Vickie", 38); #PRINT MY HASHES TO THE BROWSER print "%coins"; print "<br />"; print "%ages";
    Geez. I'm sure the noobs will have a swell time with that example (especially in light of everything they've "learned" up to that point).

    In response to Lady_Aleena's concerns, I think it'll be better not to draw any further attention to sites like this; even citing them for how bad they are just gets them more attention, which probably moves them perversely higher in the google rankings, and encourages the feeble-minded diletantes who create this kind of doggerel to keep it up.

Re: Comment on
by grinder (Bishop) on Oct 04, 2007 at 08:46 UTC

    Owwww. My eyes! My brain!

    This is so bad, it's fantastic. I particularly enjoyed the section on DBI. The code could not even be compiled, due to the missing semi-colon after use DBD::Mysql (which, to add insult to injury, is entirely superfluous to begin with). The SQL contains errors as well, which is satisfying in a perversely language-agnostic kind of way.

    And as a finishing touch, I appreciated the 2003-2008 copyright date. It's all future-proofed!

    • another intruder with the mooring in the heart of the Perl

Re: Comment on
by hangon (Deacon) on Oct 04, 2007 at 03:54 UTC

    The first thing I noticed is that this Perl tutorial is written in PHP, which did not inspire me to bother looking around any further.

      I won't read it, if it is in Perl. If a guy does not know Perl's strength and weakness, how can he teach others Perl. Perl is no longer the right tool for web servers.

        Right? And what is if I may ask? ASP.Net? Some overcomplex Java-based many-megabyte framework? Slow Ruby with its one true way and virtualy no support for Unicode?

Re: Comment on
by Anonymous Monk on Oct 04, 2007 at 09:23 UTC
    I left a message in the site comment area.
    This tutorial is the worst document I have read in a very long time.
    Shame on you. If you don't know zit about Perl, have the decency of shutting up, instead of becoming a laughing stock.
    See reasons here:
    And this is the answer I got.
    Thanks for pointing out this problem to me. I'll see that these problems get fixed, as that site you linked to contained a great deal of criticism that will definitely make Tizag's Perl tutorial a better resource.
    I'm not sure what you meant when you said "instead of becoming a laughing stock" but I'm guessing it's along the lines of "you suck". Tizag wasn't written by one person, but your criticism seems well founded and will be addressed.

      You probably should have been more constructive. But obviously they handled your flame with modesty and dignity.

Re: Comment on
by Cop on Oct 04, 2007 at 18:30 UTC

    This also brought up the potential truth that most Perl programmers out there are like this, and Perl as a language encouraged some of the bad habits.

    Perl is usually used for something quick and dirty, nothing wrong with that, as from time to time, you have to do things that are quick and dirty.

    In the world out there, the trust for Perl is thin.



      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        Trolls are stupid posts, not those posts that you hate.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://642535]
Approved by Sidhekin
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2018-01-16 23:20 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (193 votes). Check out past polls.