Here is a code example as requested.

The print statements in LDAPerror work fine. They display information in my web browser. I don't know why this works since I'm not printing the header anywhere. If I put a print statement in the main body of my code, I get an internal server error (as I should).

Thanks,
Shiva

#!/usr/bin/perl use CGI; use Net::LDAP; use Net::LDAP::Entry; use Net::LDAP::Util qw( ldap_error_name ldap_error_text); #prepare entry $entry = Net::LDAP::Entry->new(); $addinfo = CGI->new(); my $index = 5000; my($sec, $min, $hour, $day, $mon, $year, $wday, %yday, $isdst) = local +time; $mon += 1; $year += 1900; $dn = "index=" . $index . ", o=cert"; $entry->dn($dn); $entry->add('objectclass' => 'certentry', 'index' => $index, 'openedOn' => $year . $mon . $day . '000000', ); #bind to server $ldap = Net::LDAP->new("shiva.mydomain.com", port => 389) || die("Failed to connect to LDAP host.\n"); $mesg = $ldap->bind("cn=root", password => "root", version => 3); LDAPerror("Bind", $mesg); #add entry to server $mesg = $ldap->add($entry); LDAPerror("Adding", $mesg); #unbind $ldap->unbind; sub LDAPerror { my ($from,$mesg) = @_; print "\n$from\nReturn code: ",$mesg->code ; print "\tMessage: ", ldap_error_name($mesg->code); print " :", ldap_error_text($mesg->code); print "MessageID: ",$mesg->mesg_id; print "\tDN: ",$mesg->dn; print "\n"; #--- # Programmer note: # # "$mesg->error" DOESN'T work!!! # #print "\tMessage: ", $mesg->error; #----- }

In reply to Re: Re: "print" in a CGI script. by shivapd
in thread "print" in a CGI script. by shivapd

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.