...here's another possibility. Certainly JNI is an excellent way to call native functions (such as those in the Perl libraries) directly from a class file, but I will bet that your scripts don't convert easily into something that would work this way.

And what would be easiest varies from programmer to programmer. (When someone tells me what "would just be the easiest" I translate that to mean "if I had to do the job, it would be easiest to...")

And I'm willing to bet that the use of regexes in your existing scripts will not translate well to Java Patterns due to the many nuances of regex implementation in Perl and our inability to avoid using those nuances over and over again.

So what I was thinking would do the trick is to build a small network server in Perl that is launched at the same time as your application and which answers on a port known to your application. Then, when the time comes to call for a file operation, the Java class you provide will actually send a request to your already waiting Perl server which would process the job.

So if you find out from your application architects how to supply a Java class that will service the request, then write such a class that forwards the request to your Perl server. The server could be very simple, just listen on a designated port, then receive a formatted request to service a file, do that job and then go back to listening.

This would result in the elimination of the overhead caused by process creation. The Perl server could be simple enough to fit in about two printed pages of code, and it could provide the gateway to the rest of your scripts.

And you'd learn a great deal about both Perl and Java as you write it!

...All the world looks like -well- all the world, when your hammer is Perl.
---v


In reply to Re: Calling perl from java by agentv
in thread Calling perl from java by fletcher_the_dog

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.