Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

How easy it is to make mistakes

by tobyink (Canon)
on May 23, 2017 at 10:54 UTC ( [id://1190951]=perlmeditation: print w/replies, xml ) Need Help??

So, I don't use CGI a lot much these days. But I recently wrote a little joke module and decided to make a little HTML form interface for it. Plack would be a sensible way of doing the interface, but this was just a silly little thing and I was feeling lazy, so I coded it up using CGI instead. I'd used Moo rather than Moose so speed shouldn't have been an issue.

I uploaded it to the server and visited the page and it just showed me my Perl source code. Hmmm…

Create .htacccess and add the following lines:

Options +ExecCGI AddHandler cgi-script .cgi .pl

Visit the page again… still showing the source code. Hmmm…

Scratch head for five minutes. Open up httpd.conf, add:

<Directory /path/to/my/vhost/> AllowOverride all </Directory>

Visit the page again… still showing the source code. Hmmm…

SSH into the server and run ./myscript.cgi from the command line.

"uniq" is not exported by the List::Util module

Okay, I must have an old version of it. Upgrade.

Visit the page again… still showing the source code. Hmmm…

Stop using List::Util entirely.

sub uniq { my %seen; grep !$seen{$_}++, @_; }

Visit the page again… still showing the source code. Hmmm…

Scratch head for ten minutes. Rename to ./myscript.pl.

Visit the page again… still showing the source code. Hmmm…

Create the following file and mark it as executable:

#!/bin/sh echo "Content-Type: text/plain"; echo ""; echo "Hello world";

Visit my new page… also showing the source code. Hmmm…

Scratch head some more.

Consider buying anti-headlice shampoo.

Finally… FINALLY… after about TWO HOURS I figure out the problem! It was…

Replies are listed 'Best First'.
Re: How easy it is to make mistakes
by hippo (Bishop) on May 23, 2017 at 11:34 UTC

      Well spotted.

      *facepalms

        I spent several hours chasing a s/}/)/ once, editing and re-editing a script while the error message jumped around by dozens of line numbers. Two hours on a misspelling seems quite tame. :P

Re: How easy it is to make mistakes
by shmem (Chancellor) on May 23, 2017 at 13:59 UTC

    Bought a good mechanical keyboard (Leopold, brown cherry switches, blank). At least, my bugs aren't at the keyboard level anymore. No bouncing keys since ;-)

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

      I think the problem is that in a long string of letters without ascenders (letters that reach up higher than "x", like "t" or "b") or descenders (letters that drop lower than "x" like "g" or "p"), it can be hard to spot typos — the letters can blend in together. Ascenders and descenders give a word its shape.

      This might be something to think about when designing easy-to-use APIs.

        Yes, yes. And this is why, counter-intuitively to most, ALL CAPS IS HARDER TO READ than plain sentence casing.

Re: How easy it is to make mistakes
by talexb (Chancellor) on May 24, 2017 at 03:55 UTC

    Oh, dear. Well, thanks for sharing your pain .. I used Mojo for my last little foray into CGI-land, and didn't have to worry about good old .htacess .. I think it's getting to be time to learn Plack properly, rather than just 'Good enough to get this small job done' ..

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Re: How easy it is to make mistakes
by karlgoethebier (Abbot) on May 24, 2017 at 09:57 UTC
    "Respice post te, hominem te esse memento"

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    Furthermore I consider that Donald Trump must be impeached as soon as possible

Re: How easy it is to make mistakes
by sundialsvc4 (Abbot) on May 30, 2017 at 15:04 UTC

    Q:   Why do computer programmers have flat heads?

    A:   (facepalm!)   “D’oh!”

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://1190951]
Front-paged by Discipulus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-16 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found