Closed Thread
Results 1 to 3 of 3

Thread: Splitting Error

  1. #1
    policy is offline Newbie
    Join Date
    Jul 2006
    Posts
    4
    Rep Power
    0

    Splitting Error

    I'm using this code to split:

    [HIGHLIGHT="Perl"]# Split the lines by *
    @code = split(/*/, $my_lines);[/HIGHLIGHT]

    but I get this error:

    "Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE / at c:\projects\line_split.pl line 31"

    Any ideas how to fix this or why this error is generated? I can split with:

    [HIGHLIGHT="Perl"]# Split the lines by *
    @code = split(/'/, $my_lines);[/HIGHLIGHT]

    and everything works fine.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    KevinADC is offline Programmer
    Join Date
    Jan 2007
    Posts
    125
    Rep Power
    0
    '*' is a quantifier, it means: zero or more when used in a regular expression, which is what split(//) is. If you want to split on a literal * you have to escape it:

    @code = split(/\*/, $my_lines);

    or use single-quotes:

    @code = split('*', $my_lines);

  4. #3
    policy is offline Newbie
    Join Date
    Jul 2006
    Posts
    4
    Rep Power
    0
    That works! Thanks

    I didn't think about it being a quantifier.

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. Problem with splitting
    By Sinipull in forum Java Help
    Replies: 3
    Last Post: 03-29-2010, 02:15 PM
  3. Splitting...
    By Chan in forum C# Programming
    Replies: 3
    Last Post: 08-06-2007, 05:41 AM
  4. Splitting by plus (+)?
    By Cosmet in forum Perl
    Replies: 4
    Last Post: 05-21-2007, 05:23 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