X_Bones has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to write a simple script that checks the Windows registry for the value of a certain key, then output it to a Web browser. The following looks fine when run from a command-line window:

#!C:\perl\bin\perl -w

my $Registry;
use Win32::TieRegistry (TiedRef=>\$Registry, Delimiter=>"/", ArrayValues=>1);
my $env = $Registry->{"CUser/Control Panel/Desktop/"};
my $wallpaper = $env->{"/Wallpaper"};
$foo = $wallpaper->[0];
#print ("< HTML>< HEAD>< /HEAD>< BODY>

", $foo, "

< /BODY>< /HTML>"); #end file

However, when I try running it through a Web browser, it chokes for some reason. Nothing gets sent to the browser, but I know it's not bad HTML since I verified it in the command-line window (the spaces in the above HTML code are there so PM doesn' t try to interpret it literally; they're not in the real script). Has anyone dealt with this problem before and know of a fix? Any help would be greatly appreciated.
Thanks in advance, Dan
  • Comment on Win32::TieRegistry, command-line vs. Web page

Replies are listed 'Best First'.
Re: Win32::TieRegistry
by Abigail (Deacon) on Jul 15, 2000 at 20:51 UTC
    Well, first of all, you have outcommented the print statement, so I wouldn't expect any output at all. Furthermore, even if the print statement wasn't outcommented, the program does not send an HTTP header, just some HTML. The poor browser expects HTTP, and will hence think the server went bananas. You also never check for errors; you assume every call you make succeeds. I don't know much about Win32; I can't recall that I ever used it. I heard it doesn't have much security, but is the security that bad that a web server can access a users control panel? If not, then that might be your problem.

    -- Abigail

Re: Win32::TieRegistry
by c-era (Curate) on Jul 15, 2000 at 20:53 UTC
    You fogot to print your header. Add this line of code before you print anything to a web browser.
    print "Content-type: text/html\n\n";
    P.S. Please use <code> and </code> around your code.
RE: Win32::TieRegistry, command-line vs. Web page
by wardk (Deacon) on Jul 18, 2000 at 02:09 UTC
    print ("Content-type: text/html\n\n< HTML>< HEAD>< /HEAD>< BODY>< P>", + $foo, "< /P>< /BODY>< /HTML>"); #end file