Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Splitting by plus (+)?


  • Please log in to reply
4 replies to this topic

#1 Cosmet

Cosmet

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 58 posts

Posted 17 May 2007 - 10:56 AM

When I try to split by a plus using this 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????
  • 0

#2 v0id

v0id

    Retired

  • Retired Mod
  • PipPipPipPipPipPipPipPip
  • 2313 posts

Posted 17 May 2007 - 11:23 PM

It's long time ago I last played with Perl, so I'm not sure about this.
Try doing this, instead of your code:
@segments = split('+', $n);
or if that doesn't work, try:
@segments = split(/\+/, $n);

  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#3 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 18 May 2007 - 04:42 AM

I'm not sure if those two methods work but I did try this:

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

You had it right except you were using "" instead of '. The + needs an escape character (\) which you had correct.
  • 0

#4 KevinADC

KevinADC

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 125 posts

Posted 19 May 2007 - 02:49 PM

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.
  • 0

#5 Cosmet

Cosmet

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 58 posts

Posted 21 May 2007 - 04:23 AM

Thanks for your help guys. I've never heard of the "m" before - I always add this to split functions?
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download