Home > Archive > PERL CGI Beginners > September 2005 > RE: Use of uninitialized value
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
RE: Use of uninitialized value
|
|
| Charles K. Clarkson 2005-09-13, 6:55 pm |
| DBSMITH@OhioHealth.com [mailto:DBSMITH@OhioHealth.com] wrote:
: I'd rather send the whole thing b/c I also would like a critique
: as well. Here she is!
First glaring item: you cannot nest subroutines. To perl, the
following are equivalent.
===========
print "blah";
if ( $which_radio_button eq 'All-Clients' ) {
&viewall();
sub viewall {
# do something;
}
} elsif ( $which_radio_button eq 'Backup-Tapes' ) {
&viewbkups();
sub viewbkups {
# do something else;
}
}
===========
print "blah";
if ( $which_radio_button eq 'All-Clients' ) {
viewall();
} elsif ( $which_radio_button eq 'Backup-Tapes' ) {
viewbkups();
}
sub viewall {
# do something;
}
sub viewbkups {
# do something else;
}
===========
So there's no advantage to placing the subs in line and taking
them out makes your code more readable.
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
| |
| DBSMITH@OhioHealth.com 2005-09-14, 6:55 pm |
| what do you mean I cant? It is logically working! Is this is
recommedation for more readibility and thats it? Or is this Perl best
practice thingy?
thank you!
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
"Charles K.
Clarkson"
<cclarkson@htcomp To
.net> <beginners-cgi@perl.org>
cc
09/13/2005 02:02
PM Subject
RE: Use of uninitialized value
DBSMITH@OhioHealth.com [mailto:DBSMITH@OhioHealth.com] wrote:
: I'd rather send the whole thing b/c I also would like a critique
: as well. Here she is!
First glaring item: you cannot nest subroutines. To perl, the
following are equivalent.
===========
print "blah";
if ( $which_radio_button eq 'All-Clients' ) {
&viewall();
sub viewall {
# do something;
}
} elsif ( $which_radio_button eq 'Backup-Tapes' ) {
&viewbkups();
sub viewbkups {
# do something else;
}
}
===========
print "blah";
if ( $which_radio_button eq 'All-Clients' ) {
viewall();
} elsif ( $which_radio_button eq 'Backup-Tapes' ) {
viewbkups();
}
sub viewall {
# do something;
}
sub viewbkups {
# do something else;
}
===========
So there's no advantage to placing the subs in line and taking
them out makes your code more readable.
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
--
To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
For additional commands, e-mail: beginners-cgi-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
|
| --- DBSMITH@OhioHealth.com wrote:
> what do you mean I cant? It is logically working! Is this is
> recommedation for more readibility and thats it? Or is this Perl
> best
> practice thingy?
Because Perl subroutines are not lexically scoped.
sub foo {
sub bar {
return 'bar';
}
print bar();
}
print bar();
If you really need lexically scoped subroutines, assign an anonymous
subroutine to a scalar:
sub foo {
my $bar = sub {
return 'bar';
};
print $bar->();
}
# no access to $bar from here
Cheers,
Ovid
--
If this message is a response to a question on a mailing list, please send
follow up questions to the list.
Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
|
|
|
|
|