Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Running local code on other machines

by spx2 (Chaplain)
on Apr 07, 2010 at 11:18 UTC ( #833262=note: print w/ replies, xml ) Need Help??


in reply to Re: Running local code on other machines
in thread Running local code on other machines

yes, but how do I serialize a sub and send it on the socket ?


Comment on Re^2: Running local code on other machines
Re^3: Running local code on other machines
by rubasov (Friar) on Apr 07, 2010 at 11:38 UTC
    Umm, serializing a sub is not easy in perl as far as I know, but what about storing your sub's source as a string, send it over the socket as plain text, then eval at the other end of the socket?
    my $sub_str = q{ sub { my $n = shift; return $n + 1; } }; # send the string through the socket # at the far end of the socket: my $sub_ref = eval $sub_str; print $sub_ref->(2), "\n";
Re^3: Running local code on other machines
by BrowserUk (Pope) on Apr 07, 2010 at 11:42 UTC

    Be aware that unless your sub is very trivial, you have much more to do than just serialising the sub. If that sub make use of any modules, you'll also have to arrange for those modules to be loaded and initialised at the other machine also. And if those modules use any modules...


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      basically the sub should be just based on its own parameters and nothing else.

        Then take a look at Data::Dumper::Deparse()


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Running local code on other machines
by JavaFan (Canon) on Apr 07, 2010 at 17:21 UTC
    Put it in a module, and use a source control system. (git, hg, svn, cvs, ...)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://833262]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-09-22 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (185 votes), past polls