473,471 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

splitting problem

Jan
Hi!
I have to split a string with a pattern which contains sometimes chars
like + \ (the code is needed in an interpreter, written in Perl, of my
own scripting language, so I never know the pattern exactly).

split(/$pattern/, $string);

It works well most of all time, but if the pattern is + the execution
of the program stops and perl prints an error message.

$pattern = '+';
split(/"$pattern"/, $string); #ok

$pattern = '#';
split(/"$pattern"/, $string); #doesn't work really, but no
error
#occurs

Can anyone tell me how to solve this problem?
Jul 19 '05 #1
3 2201
Jan wrote:
I have to split a string with a pattern which contains sometimes chars
like + \ (the code is needed in an interpreter, written in Perl, of my
own scripting language, so I never know the pattern exactly).

split(/$pattern/, $string);

It works well most of all time, but if the pattern is + the execution
of the program stops and perl prints an error message.

$pattern = '+';
split(/"$pattern"/, $string); #ok

$pattern = '#';
split(/"$pattern"/, $string); #doesn't work really, but no error
#occurs

Can anyone tell me how to solve this problem?


I don't think any of those works, since you are actually trying to
split on the strings '"+"' and '"#"'.

You should escape special characters. Try:

split /\Q$pattern/, $string;

Also, stop asking questions in this newsgroup. It's defunct. Use
comp.lang.perl.misc instead.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #2
÷ ÐÉÓØÍÅ Fri, 31 Oct 2003 00:35:15 -0800, Jan ÎÁÐÉÓÁÌ:
Hi! Hi
split(/$pattern/, $string);

It works well most of all time, but if the pattern is + the execution
of the program stops and perl prints an error message.

This is most like '+' means repeat more than zero.
I recommend do something like that if you want pattern to be a string
(not regexp):
$pattern = "string";
$qpattern = quotemeta($pattern)
split(/$pattern/,$string);
--
With best wishes Nikolay
mail: ni*****@asu.ntu-kpi.kiev.ua
ICQ#: 136497739

Jul 19 '05 #3
Jan
Thank you, the examples work!
.... and excuse me about posting this thread in the wring newsgroup.
Jan
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: robsom | last post by:
Hi, I have a problem with a small python program I'm trying to write and I hope somebody may help me. I'm working on tables of this kind: CGA 1988 06 21 13 48 G500-050 D 509.62 J.. R1 1993 01...
10
by: Angelo Secchi | last post by:
Hi, I have string of numbers and words like ',,,,,,23,,,asd,,,,,"name,surname",,,,,,,\n' and I would like to split (I'm using string.split()) it using comma as separator but I do not want to...
3
by: William Ahern | last post by:
I'm looking for resources on splitting and merging XML trees. Specifically, on methods to pare large XML documents into smaller documents which can be merged later. Off of the top of my head, I...
5
by: Peter Oliphant | last post by:
I was thinking it might be a good idea to split this newsgroup into different newsgroups, depending on the version of VS C++.NET being discussed. Thus, there would be 2002, 2003, and 2005...
0
by: melis | last post by:
Hi all, I am new to MFC, and cannot find a way to the following problem :( What I am trying to do is just to split the window into two parts, tyring to have a CFormView or CDialog on left and a...
2
by: CharChabil | last post by:
Using Vb.net 2005, I want to read each part in this string in an array (splitting the string) ----------- A1/EXT "BK82 LB73 21233" 105 061018 1804 ----------- That Code that i used is as follow:...
9
by: conspireagainst | last post by:
I'm having quite a time with this particular problem: I have users that enter tag words as form input, let's say for a photo or a topic of discussion. They are allowed to delimit tags with spaces...
2
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to...
6
by: jacc14 | last post by:
Good morning all. I have been working on a database for the past couple of weeks and it is pretty nippy. I have an ODBC link in there from another software program. Since splitting it and...
37
by: xyz | last post by:
I have a string 16:23:18.659343 131.188.37.230.22 131.188.37.59.1398 tcp 168 for example lets say for the above string 16:23:18.659343 -- time 131.188.37.230 -- srcaddress 22 ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.