Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Could you look over my completed (but not working) short .cgi script?

by GrandFather (Saint)
on May 31, 2014 at 22:34 UTC ( [id://1088143]=note: print w/replies, xml ) Need Help??


in reply to Could you look over my completed (but not working) short .cgi script?

Using strictures (use strict; use warnings;) is excellent and something you should always do. Batch declaring variables negates the most valuable diagnostic that strict provides. In fact what you wreck is exactly what your comment describes as the reason for using strict! Consider this fragment of your code:

#prevent Perl from creating undeclared variables use strict; #declare variables and assign variables my ($item, $C_basket, @basket); #make cookies $C_basket = cookie( -name => "Basket", -value => "@basket", -path => "../../cgi-bin/chap11" );

Do you see anything wrong there? How about if we rewrite it this way and run it:

use strict; #make cookies my $C_basket = cookie( -name => "Basket", -value => "@basket", -path => "../../cgi-bin/chap11" );

Now you get an error: Global symbol "@basket" requires explicit package name which is strict's way of saying "I haven't seen the variable @basket before". In other words, @basket is undefined.

So, what do you expect the cookie value to be? What it will be is an empty string, but if you intended that you should write that. If you didn't intend that, batch declaring variables has masked exactly the sort of bug strict should alert you to.

Perl is the programming world's equivalent of English

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1088143]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-26 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found