When I try to split by a plus using this code:
I get the error "Quantifier follows nothing in regex; marked by <-- HERE in m/+ <-- HERE"Code:@segments = split("\+", $n);
I have checked and $n is actually a value with many plus marks in it. Anyone know how to fix this????
It's long time ago I last played with Perl, so I'm not sure about this.
Try doing this, instead of your code:
or if that doesn't work, try:Code:@segments = split('+', $n);
Code:@segments = split(/\+/, $n);
I'm not sure if those two methods work but I did try this:
You had it right except you were using "" instead of '. The + needs an escape character (\) which you had correct.Code:@segments = split('\+', $n);
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.
Thanks for your help guys. I've never heard of the "m" before - I always add this to split functions?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks