macosperldarwin

Darwin Streaming Server install problems os x


My problem is the same as the one mentioned in this answer. I've been trying to understand the code and this is what I learned:

It is failing in the file parse_xml.cgi, tries to get messages (return $message{$name}) from a file named messages (located in the html_en directory). The $messages value comes from the method GetMessageHash in file adminprotocol-lib.pl:

sub GetMessageHash
{
   return $ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"}
}

The $ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} is set in the file streamingadminserver.pl:

$ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} = $messages{"en"}

I dont know anything about Perl so I have no idea of what the problem can be, for what I saw $messages{"en"} has the correct value (if I do print($messages{"en"}{'SunStr'} I get the value "Sun")).

However, if I try to do print($ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"}{'SunStr'} I get nothing. Seems like $ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} is not set

I tried this simple example and it worked fine:

$ENV{"HELLO"} = "hello";
print($ENV{"HELLO"});

and it works fine, prints "hello".

Any idea of what the problem can be?


Solution

  • Looks like $messages{"en"} is a HashRef: A pointer to some memory address holding a key-value-store. You could even print the associated memory address:

    perl -le 'my $hashref = {}; print $hashref;'
    HASH(0x1548e78)
    

    0x1548e78 is the address, but it's only valid within the same running process. Re-run the sample command and you'll get different addresses each time.

    HASH(0x1548e78) is also just a human-readable representation of the real stored value. Setting $hashref2="HASH(0x1548e78)"; won't create a real reference, just a copy of the human-readable string.

    You could easily proof this theory using print $ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} in both script.

    Data::Dumper is typically used to show the contents of the referenced hash (memory location):

    use Data::Dumper;
    print Dumper($messages{"en"});
    # or 
    print Dumper($ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"});
    

    This will also show if the pointer/reference could be dereferenced in both scripts.

    The solution for your problem is probably passing the value instead of the HashRef:

    $ENV{"QTSSADMINSERVER_EN_SUN"} = $messages{"en"}->{SunStr};
    

    Best Practice is using a -> between both keys. The " or ' quotes for the key also optional if the key is a plain word.

    But passing everything through environment variables feels wrong. They might not be able to hold references on OSX (I don't know). You might want to extract the string storage to a include file and load it via require.

    See http://www.perlmaven.com/ or http://learn.perl.org for more about Perl.