Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4497806

Java split methods work differently from Perl split methods

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.4.0
    • core-libs
    • None
    • beta3
    • generic
    • generic
    • Verified

      Date: Tue, 28 Aug 2001 15:55:10 -0700
      From: Jim Balter <###@###.###>


      The Java folks decided to "borrow" the split function from Perl.
      Unfortunately, their appears to have been some misunderstanding of
      the Perl functionality. According to the Java 1.4 documentation at
       
      http://java.sun.com/j2se/1.4/docs/api/java/util/regex/Pattern.html

        The input "boo:and:foo", for example, yields the following results with these parameters:

        Regex Limit Result
           : 2 { "boo", "and" }

      But this is *not* what Perl's split does, and misses the
      point of the "limit" argument. The perl program
       
      perl -le 'print join(" ", split(":", "boo:and:foo", 2))'

      prints

      boo and:foo

      *not*

      boo and
       
      The point of the "limit" argument is to limit the number
      of times the pattern is applied, so that, e.g., only the
      first ':' is treated as a separator. But the Java version
      doesn't provide this functionality, and this disparity will
      cause confusion for people who are exposed to both languages.

      Thanks for your time and attention.

            mmcclosksunw Michael Mccloskey (Inactive)
            mr Mark Reinhold
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: