Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: A Perl vs. Java fight brews

by emazep (Priest)
on Jul 25, 2006 at 10:11 UTC ( #563466=note: print w/ replies, xml ) Need Help??


in reply to Re^2: A Perl vs. Java fight brews
in thread A Perl vs. Java fight brews

Though regex support in Java was introduced several years ago (but not that many: JDK 1.4 AFAIK, 2002 circa, if we mean the java.util.regex package), it still doesn't offer advanced things such as match-time code evaluation, match-time pattern interpolation and conditional interpolation.

So, for example, with a Java regex you can't build a recursive pattern (to check for instance if the parentheses in a text are balanced), while in Perl you can ;-)

Update

It can also be interesting to see how more verbose Java regexes are compared to Perl regexes.
Here is a simple Perl example:

my $pat = qr/a+b/; my $res = "aaab" =~ $pat;
and here is its Java counterpart:
import java.util.regex.*; Pattern pat = Pattern.compile("a+b"); Matcher mat = pat.matcher("aaab"); boolean res = mat.matches();
Really, the above 2 last lines could be substituted by the following somewhat shorter code:
boolean res = pat.matcher("aaab").matches();
but if you don't explicitly instantiate a Matcher object, you can't have several things such as match, prematch, postmatch etc. which Perl gives you for free (through the various predefined variables $&, $`, $' etc.)

Ciao, Emanuele.


Comment on Re^3: A Perl vs. Java fight brews
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2015-07-29 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls