Closed Thread
Results 1 to 5 of 5

Thread: Splitting by plus (+)?

  1. #1
    Cosmet is offline Learning Programmer
    Join Date
    Oct 2006
    Posts
    58
    Rep Power
    0

    Splitting by plus (+)?

    When I try to split by a plus using this code:

    Code:
    @segments = split("\+", $n);
    I get the error "Quantifier follows nothing in regex; marked by <-- HERE in m/+ <-- HERE"

    I have checked and $n is actually a value with many plus marks in it. Anyone know how to fix this????

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42
    It's long time ago I last played with Perl, so I'm not sure about this.
    Try doing this, instead of your code:
    Code:
    @segments = split('+', $n);
    or if that doesn't work, try:
    Code:
    @segments = split(/\+/, $n);

  4. #3
    Jordan Guest
    I'm not sure if those two methods work but I did try this:

    Code:
    @segments = split('\+', $n);
    You had it right except you were using "" instead of '. The + needs an escape character (\) which you had correct.

  5. #4
    KevinADC is offline Programmer
    Join Date
    Jan 2007
    Posts
    125
    Rep Power
    0
    the problem is when you use alternative delimiters for a regexp instead of the default / / you should almost always add the "m" (or other operator) to the beginning of the regexp so perl is clear on what is happening:

    @segments = split(m"\+", $n);

    the first argument to split is a regular expression, not a string. So use / / unless there is a reason to use alternative delimiters.

    I think the single-quotes are recognized and supported by perl to emulate awk syntax. But any other delimiters besides // must include the operator.

  6. #5
    Cosmet is offline Learning Programmer
    Join Date
    Oct 2006
    Posts
    58
    Rep Power
    0
    Thanks for your help guys. I've never heard of the "m" before - I always add this to split functions?

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. splitting
    By SpaceCowboy in forum C and C++
    Replies: 2
    Last Post: 12-01-2010, 04:58 PM
  2. splitting up a textfile
    By Shaddix in forum Java Help
    Replies: 10
    Last Post: 06-14-2009, 09:12 AM
  3. Splitting Error
    By policy in forum Perl
    Replies: 2
    Last Post: 09-21-2007, 10:13 AM
  4. Splitting...
    By Chan in forum C# Programming
    Replies: 3
    Last Post: 08-06-2007, 05:41 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts