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

Hi there Monks. I have studied the parchments on google...only to find them blinding the result I am truly after. What does "res" actually do in the below? Is it a "resolution?" Like a context or something? I can't find any references to this anywhere. Also a brief explanation of "sub" within the scope of res and this snipped would be greatly appreciated.

Thanks

my %pages = ( index => sub { res qq[ <html><body> Example text </body></html> ]; }

Replies are listed 'Best First'.
Re: what does "res" do?
by Old_Gray_Bear (Bishop) on Jul 06, 2008 at 13:20 UTC
    Your code appears to have come from GUI with HTTP::Daemon. A couple of lines prior to the one you cited is a line reading use CGI::Simple;. Do the Docs for CGI::Simple say about a res method? Do the Docs for other modules in the code sample talk about a res method or a res() function call?

    This is a somewhat circumlocutious way of saying "It All Depends on the context, Grasshopper". You research the code, given the clues available, and determine the truth based on your discoveries.... (And don't forget that the "It's a Typo!" card is often played in code you find on the Web.)

    ----
    I Go Back to Sleep, Now.

    OGB

      Your code appears to have come from GUI with HTTP::Daemon. A couple of lines prior to the one you cited is a line reading use CGI::Simple;...

      This is a ... way of saying "It All Depends on the context, Grasshopper"...

      Hmm. But what about that bit on the cited page (GUI with HTTP::Daemon) that says:

      sub res{ HTTP::Response->new( RC_OK, OK => [ 'Content-Type' => 'text/html' ], shift ) }
      I suspect this would override any definition for "res" that might be found in CGI::Simple or any other module used by that code snippet, and eliminate any ambiguity about what "res" means in the given context. (So all that remains is to figure out what HTTP::Response->new() does, and we can only hope that davegx will be able to work that out.)

      Then again, it's possible the OP was quoting from some other source... who knows?

Re: what does "res" do?
by ikegami (Patriarch) on Jul 06, 2008 at 13:52 UTC

    There is no builtin by that name.
    There is no operator by that name.

    It's either a function in your code or one imported from a module you loaded. We can't possibly guess what it does without seeing the function or knowing which module it came from.

Re: what does "res" do?
by jethro (Monsignor) on Jul 06, 2008 at 13:01 UTC
    Please post code with <code> tags. Then we can be sure that no elements vanish in the markup.

    As it stands your example fails not only because res is undefined (could be a subroutine name) but because the qq... construct afterwards would produce syntac errors in its posted form.

Re: what does "res" do?
by Anonymous Monk on Jul 06, 2008 at 11:29 UTC
    Its a secret. Where did you find that code?