[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Calling sub-routine



on 12/01/2000 05:13 AM, Amitava Basu at incas@vsnl.net wrote:

> Hello Everyone:
> 
> Many many thanks to all of you for helping me out.  I am
> amazed how
> many perl gurus responded to my help.  It is far from being
> complete.
> I am trying to figure out the following:
> ====================================================
> # Undefined subroutine &main::PrintHeader called.
> File 'LC 2:MacPerl ƒ: formregistration.pl'; Line 4
> ====================================================
> Apparently there seems to be some problem with the
> subroutine.  I have
> added to subroutine at the end.  One for saving the incoming
> data and
> the other for mailing confirmation.

it's simple.. you haven't defined the sub yet, and you are trying to use it
before the code knows what it is.
 
> I do not know how to proceed to the next step.
> 
> Regards
> 
> Amitava
> 
> #!/usr/local/bin/perl -w
> push (@INC,"/usr/localbusiness/http/accn.com/cgi-bin");
> use CGI qw(:standard :html3 -no_xhtml);

declare your subs if you want to use them before you describe them with code
(i.e. if you want to group all your subs at the end, then declare them at
the beginning) 

sub PrintHeader; # <- declared but not defined.

> print &PrintHeader;

you no longer have to use the & configuration on subs with MacPerl 5.20r4
(Perl 5.004) and later. You can delineate it with something like
print_header(); to indicate it's a sub with no arguments being passed to it,
but even that isn't entirely necessary always.

I would recommend NOT using the StudlyCaps in your code. use 'print_header'
instead. For some weird reason, people in the perl community look down on
that (why, I Have no idea.. whatever way your brain works best for you, is
the way *I* think code should be written, but if other people will have to
maintain it, then consider what I said.)
 
> &ReadParse(*registration_data);
> print << "HEAD";
> <html>
> <head>
> <title>Aztec Registration Form</title>
> </head>
> <body>
> HEAD

aCk no no not like this ^

> if (length($registration_data{"FirstName"}) > 0  &&
> length($registration_data{"LastName"}) > 0) {
> print<<"EOP";
> <h3>
> Thank you $registration_data{"FirstName"}
> $registration_data{"LastName"}
> for registering your name with Aztec. You will now verify
> the
> information entered in the form. Please Correct if
> necessary</h3>
> EOP

No, really, OPEN up CGI.pm in Shuck and READ like crazy.. ALSO read like
crazy the Website at Lincoln Stein's homepage which contains even MORE
examples on how to use CGI.pm properly.

I'm serious. You haven't quite 'got it' yet, but when you do, the lightbulb
going off will blind you temporarily. =:o

Finding that thing was like an epiphany .. Immediately the idea I wanted to
accomplish crystallized into a vision, and within three weeks of *starting
to learn perl* mind you, the task was complete. (with some assistance and
pointers from the kind folks of comp.lang.perl.misc)


-- 
Scott R. Godin            | e-mail : mactech@webdragon.net
Laughing Dragon Services  |    web : http://www.webdragon.net/



# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org