-2

I am completely new to cgi concepts.

I'm given a task to convert a Perl cgi script to Java program.

I understood that the require 'file.ext' command in Perl includes the file available for code in the Perl script.

Because of the very limited resources and improper documentation I couldn't find any proper info.

Is there any Java equivalent to do the same action that require in Perl does?

Anudeep
  • 255
  • 1
  • 3
  • 8
  • Perl programs are interpreted, and `require` loads and interprets another source file at _run-time_, while Java programs are compiled, and later run in a separate process, which makes loading additional code at run-time not the typical way of doing things. You probably don't want to convert Perl to Java. You want to rewrite an old CGI script as a modern Java application, because the CGI technology is what's outdated, not the Perl (or the Java). If you don't understand what any of this means, you are probably way out of your depths and require background knowledge that we cannot teach you here. – simbabque Oct 08 '18 at 17:08
  • I understand that it would be better to write whole application as modern Java application. But all my employers want is just to convert only that Perl script to Java program. Is there any good tutorial or some documentaion to follow? – Anudeep Oct 08 '18 at 17:11
  • I don't know. I am a Perl developer, and know very little about Java. Requesting off-site tutorials is off-topic on Stack Overflow though, so I doubt someone will give you any practical help. Good luck. :) – simbabque Oct 08 '18 at 17:14
  • Please. Before downvoting any question, give a proper reason. No one will be asking questions here on Stackoverflow if they can be found just with google search. Why would anyone waste their time typing lengthy self explanatory questions when they can find answers by googling? If someone posts a question here, it means that they already tried something but couldn't find what they want and came here with hope of finding the answer. What is the meaning of this simply downvoting the questions without providing any proper reason? – Anudeep Oct 08 '18 at 17:16
  • There is a close-vote as _too broad_ on your question that you can probably not see. Your question will get closed when five high reputation users vote to close (or an elected moderator). The person who cast that close vote probably also downvoted. – simbabque Oct 08 '18 at 17:20
  • On a different note, why do you want the equivalent of `require` at all? Even as a simple, stand alone program that does CGI (however that works in Java), you'd still want to use classes. You probably know how to load those. You need to translate/convert everything anyway. Keeping the same program architecture makes very little sense, since Java pretty much requires you to be object oriented, while (I guess) your Perl program is more of an old spaghetti mess, as those old CGI programs often are. So you can probably circumvent the need for a translation of `require` altogether. – simbabque Oct 08 '18 at 17:23
  • In Java, if you want to use classes from different packages, you `import` them. It doesn't do the same thing as Perl's `require`, though, because that's not how Java works. – Matt Jacob Oct 08 '18 at 18:49

1 Answers1

0

The paradigms do not map at all. In Perl, require simply reads a file and runs the code in it, and everything else happens as side effects of that. In Java, your code must be compiled, and classes are included automatically when you compile your program. See Extend a java class from one file in another java file for more answers on this topic.

Grinnz
  • 9,093
  • 11
  • 18