Ok, I'm kinda new to perl and I would like to know how I would go about debugging code when using Apache.

I was just looking at the error.log for apache but once I got all the errors sorted apache just segfaults when I try to run my script.

How do I find out what is going on? (I dont think it's apache because I tested individual bits of code as I went and my problems only started when I tried to make them all work together)



Here is the code:
#!/usr/bin/perl -w # Woot! The second version. $VERSION = 0.02; # like a good little coder use strict; # required modules use Apache; use XML::DOM; use HTML::Template; use vars qw($parsed_xml); # move this sort of stuff to a .conf file later my $xml_file = '/home/iordy/perl.iordy.net/iXML_base.xml'; # Read and parse the document my $parser = XML::DOM::Parser->new(); $parsed_xml = $parser->parsefile ($xml_file); ## main ## # &process_args(); #process arguments and move on from there. my $page_content = "page content"; &showpage($page_content); ## subs ## sub search { my ($search_for_section) = @_; my @search_section_results; foreach my $node ($parsed_xml->getElementsByTagName('section_id')){ if ($node->getAttibute('section_name') eq $search_for_section) { push @search_section_results,$node->getAttribute('section_id'); } } return @search_section_results; } sub process_args { my $r = Apache->request; my %arguments = $r->args; my $page_content; foreach my $key (keys %arguments) { my $arg = $arguments{$key}; #swap this to a switch later? if ($arg eq 'search') { foreach my $search_result (&search($arg)){ $page_content .= $search_result . "<br />"; } } else{ $page_content = "Page Error: No valid argument specified!"; } } &showpage($page_content); } # note: make this a package later on, plus add in all the other attrib +utes that a page will need. sub showpage { my ($page_content) = @_; my $r = Apache->request; $r->send_http_header('text/html'); $r->print($page_content); }



And here is the xml:
<xml> <section section_id=1 section_name="root" section_title="iordy.com -> +root"> <page_content> <page>root.html</page> </page_content> </section> <section section_id=2 section_name="art" section_title="iordy.com -> a +rt"> <page_content> <page>art.html</page> <page page_title="iordy.com -> art.2">art2.html</page> </page_content> </section> <section section_id=3 section_name="test" section_title="iordy.com -> +subtree test"> <page_content> <page page_title="iordy.com -> subtree test page1">test1.html</page> <page page_title="iordy.com -> subtree test page2">test2.html</page> </page_content> <section section_id=4 section_name="test3" section_title="iordy.com - +> subtree test2"> <page_content> <page page_title="iordy.com -> subtree test page 3">test3.html</pag +e> </page_content> </section> </section> </xml>

In reply to Debugging when using Apache-request; by IOrdy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.