Re: Variable remaining undef in one place but not another.



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
.



Relevant Pages

  • Variable remaining undef in one place but not another.
    ... the cwd on to part that starts the HTML, so that the cwd can be used in ... use warnings; ... use strict; ... sub htmlStart{ ...
    (comp.lang.perl.misc)
  • Re: File::Find module wont run recursively?
    ... my ($cwd, $ext, @list_of_files); ... warnings' pragma, remember it's lexical, and needs to be mentioned ... but a named sub doesn't.) ... file extensions in the same locations, ...
    (perl.beginners)
  • Re: Variable remaining undef in one place but not another.
    ... the cwd on to part that starts the HTML, so that the cwd can be used in ... the HTML title tag. ... use strict; ... sub htmlStart{ ...
    (comp.lang.perl.misc)
  • Re: A toughy.
    ... Do I ignore all those warnings and using add and remove just delete the darned thing? ... I have always used HTML for my personal posts and the HTML doesn't seem to ... Bug 2. ... Paying users do not have this message in their emails. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: backreferneces in search pattern
    ... Unless you control the layout of the HTML, you would be much better off ... > I am labouring since a long while already on this filter. ... because of the additional control over the warnings it affords. ... The uninitialized value might have come from a capturing parentheses ...
    (comp.lang.perl.misc)