Re: Variable remaining undef in one place but not another.
- From: Ron Bergin <rkb@xxxxxxxxxx>
- Date: Wed, 28 May 2008 15:24:20 -0700 (PDT)
On May 28, 7:58 am, Justin C <justin.0...@xxxxxxxxxxxxxx> wrote:
I have a perl program which generates a web-page. It is supposed to pass
the cwd on to part that starts the HTML, so that the cwd can be used in
the HTML title tag. It doesn't. My logs tell me it is undefined.
However, when I pass it on to another program it is defined. I'm sure
I'm just not seeing the wood for the trees... either that, or perl is
running ahead of itself and not getting an answer to the "getPage()"
subroutine.
#!/usr/bin/perl
use warnings;
use strict;
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser/;
my $page = getPage();
htmlStart();
LeftNav();
sub getPage{
my $rv = `../docs/getCwd.pl`;
return $rv;}
sub htmlStart{
my @args = ("../docs/htmlStart.pl", $page);
system(@args);}
sub LeftNav{
my @args = ("../docs/navLeft.pl", $page);
system(@args);
}
----
Here is getCwd.pl:
#!/usr/bin/perl
use warnings;
use strict;
use Cwd;
my $path = (cwd() =~ /^\/+.*\/(.*)$/);# get just the last part of the path
print "$1";
----
Here is htmlStart.pl:
#!/usr/bin/perl
use warnings;
use strict;
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser/;
my $page = pop @ARGV;
# Define the page title
my $title = "Masons Music - $page";
# Start the html document
print header;
print start_html(
-title=>$title,
-style=>{'src'=>'/docs/style.css'},
);
----
Here is navLeft.pl, where $page is passed successfully, and doesn't
throw up and undef warning:
#!/usr/bin/perl
use warnings;
use strict;
my @links = qw/contact about sales news/;
my $page = pop @ARGV;
foreach ( @SiteLinks::sequence ) {
firstPart($_);
}
sub firstPart{
if ( $page eq (pop @links) ) {
print " class=\"thisPage2\"";
}
}
----
Sorry there isn't less code, but I couldn't find a way of demonstrating
the problem with fewer lines.
As you can see, $page is passed to both of the external programs, yet in
the first it's passed to it remains undef while the second (and third,
for there is another I've not shown here) gets the value.
Any ideas what's going on? I have reduced the code above for conciseness,
I hope it's not now beyond understanding.
I thank you for any help you can give with this.
Justin.
That seams a little inefficient to me. Why not combine those scripts
and use HTML::Template? If needed, you could easily split up the
template files into header.tmpl, footer.tmpl, leftnav.tmpl, etc
http://search.cpan.org/~samtregar/HTML-Template-2.9/Template.pm
.
- References:
- Variable remaining undef in one place but not another.
- From: Justin C
- Variable remaining undef in one place but not another.
- Prev by Date: Re: Perldoc recommendation
- Next by Date: Re: Turning a dir output into a webpage ??
- Previous by thread: Re: Variable remaining undef in one place but not another.
- Next by thread: Remove a tab with backspace?
- Index(es):
Relevant Pages
|