Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

(Guildenstern) Re: "Obviously, You Will Need a Java Course..."

by Guildenstern (Deacon)
on Apr 03, 2001 at 22:43 UTC ( #69420=note: print w/replies, xml ) Need Help??


in reply to "Obviously, You Will Need a Java Course..."

Personally, I don't have much of a problem with Java. We're using it to develop our Web applications, and it works fine for that. It all boils down to using the right language for the job. Granted, Perl is great, but it's not a be all, end all solution. I'm not saying that Java is that solution either, but there are some cases where (IMHO) it's easier to get things done. Take, for example, session handling. In a Java Servlet, I just need to say something like
HttpSession session = request.getSession(); session.addAttribute("key","value");

if I want to add something to a persistent session. In Perl, this can be done (see Apache::Session), but it doesn't have the same flow to me. Sure, somebody can write a Perl session handler that works like its Java counterpart, but that's not the point I'm trying to make here. I'm saying that in this case, Java works better for me.

One of the driving design issues behind our site development is to make eveything server-side to the point of excluding client side scripting (JavaScript, VBScript,etc). This means that we must perform all of the input validation in the Java Servlets and Java Server Pages. This is a case where Perl is by far the superior language. It's so much easier to run a string through a regex than to use Java's String methods. (Of course, somebody has written a regex package for Java, but once again that's not the point I'm making.)

As far as the examples that you provide, System.out.println("Hello"); should be familiar to anyone who's had exposure to Object Oriented Programming. Since you said you're new to programming in general, I can understand your confusion.

The second example illustrates a very simple example of Java's error handling. Instead of die-ing, catching the error can let you do other things like retrying the open or notifying another process. I'm not sure if Perl supports error handling in the same manner (try and catch, or similar), but I'm sure somebody here can clue me in.

Guildenstern
Negaterd character class uber alles!

Replies are listed 'Best First'.
Re: (Guildenstern) Re: "Obviously, You Will Need a Java Course..."
by McD (Chaplain) on Apr 04, 2001 at 20:20 UTC
    Guildenstern writes:

    I'm not sure if Perl supports error handling in the same manner (try and catch, or similar), but I'm sure somebody here can clue me in.

    darobin mentions this below - use eval BLOCK with die to catch and throw exceptions:

    eval { # code that might die }; if ($@) { # $@ contains your exception }
    Peace,
    -McD

    Update: merlyn is right, of course - forgot the ";". Curse my flying fingers! :-)

      eval { # code that might die } if ($@) { # $@ contains your exception }
      Don't forget the semicolon after the eval {}. That kind of eval is an expression, not a statement, so it needs a semicolon to become a statement.

      -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2020-10-20 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (209 votes). Check out past polls.

    Notices?