Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > Perl

Perl Discussion for the PERL language - Practical Extraction and Reporting Language, is a programming language often used for creating CGI programs.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-17-2007, 02:56 PM
Cosmet Cosmet is offline
Learning Programmer
 
Join Date: Oct 2006
Posts: 58
Rep Power: 8
Cosmet is on a distinguished road
Default 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????
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 05-18-2007, 03:23 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,635
Last Blog:
CherryPy(thon)
Rep Power: 28
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

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);
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-18-2007, 08:42 AM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,228
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-19-2007, 06:49 PM
KevinADC KevinADC is offline
Learning Programmer
 
Join Date: Jan 2007
Posts: 91
Rep Power: 7
KevinADC is on a distinguished road
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-21-2007, 08:23 AM
Cosmet Cosmet is offline
Learning Programmer
 
Join Date: Oct 2006
Posts: 58
Rep Power: 8
Cosmet is on a distinguished road
Default

Thanks for your help guys. I've never heard of the "m" before - I always add this to split functions?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Splitting... Chan C# Programming 3 08-06-2007 08:41 AM
Splitting Strings with Empty Separator (Python) Matt Python 3 05-18-2007 01:27 PM


All times are GMT -5. The time now is 04:02 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads