Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Aldebaran++ that's really cool addition you got there!

Q2) How would I turn the above script into "monolithic" foreign code?

Turn your additions into a sub (a subroutine aka function) which will be a complete black box. It will take some inputs, and return some outputs (print if you must but don't forget to return all you need to return to the caller so that your sub is useful). For example:

sub func { my ($event, @planet_names) = @_; # read in parameters supplied by call +er as in func($xyz) # check that we have some names and that event contains the fields we +need # return undef on error. # caller must check if received undef! return undef unless @planet_names; return undef unless exists $event->{epoch}; ... my %returned_planets = (); for my $a_planet_name (@planet_names){ my $planet = Astro::Coords->new( planet => $name ); ... $returned_planets{$a_planet_name} = $planet; } # return to the caller results as a hashref # I always use refs for params and results. others may not. return \%returned_planets; } # end of my function # example use my $ret = func($anevent, "venus", "saturn"); die "func() failed" unless defined $ret; # and now do what you like with the results.

I am referring to the code you presented above about here:

for my $event (@events) { my $epoch = parse_event($event); my ( $MoonPhase, $MoonIllum, $MoonAge, $MoonDist, $MoonAng, $SunDist +, $SunAng ) = phase($epoch);

Then build some test cases to test your sub. Edge cases (e.g. empty planet names, wrong names) and also cases you know the result. And you are good to go :)

Todo: at this stage it is a prototype. When final, we can turn this into OO, with $event being a class. But that's much later.

Let me know how you convert your additions into a sub.

Q3) Does Data::Roundtrip cover the same ground that JSON::XS did? I can't disambiguate what XS means.

It's just a wrapper around many great modules to implement things like json2perl, perl2yaml with (hopefully correct) unicode suppprt. Don't worry about it. But you can safely replace it with calls to JSON's decode() etc. (which, as stevieb said, switches between XS or PP depending what is installed on your system) so that you have one less dependency.

BTW, I think you also provided me with an answer as to why I never use the debugger :)

bw, bliako


In reply to Re^6: a *working* JSON module (Perl's Debugger), related issues by bliako
in thread Can someone please write a *working* JSON module by cnd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-19 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found