473,385 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Spliting on multiple delimiters

Dear All,

I am currently new to perl and is experiencing difficulties with splitting and array with multiple conditions.
For example ,

I would like to spilt an element, which contains one or more of the three keywords that i would like to split the array into : Region, Site, Bond.

i tried the command

@split_feature_protein_field = split ( /\sRegion|Site|Bond/,$split_feature_protein_field1[1] ) ;

but it do not seem to work...

Does anyone have any idea on multiple condition splitting?

Thanks
Aug 1 '07 #1
2 9719
numberwhun
3,509 Expert Mod 2GB
When you are using the split function, it is going to perform the split using the delimiter that you specify in your regex. So, if you are providing several options, then it is going to try to figure that out.

Lets say your data is in the following format:

field1;field2;field3

and the date is in a file called...well.... data.txt. You would want to split using a semicolon as a delimeter. Here is how you would do it:

Expand|Select|Wrap|Line Numbers
  1. open(FILE, "<./data.txt");
  2.  
  3. while(<FILE>) {
  4.     chomp;
  5.     my $data = $_;
  6.     my @array = split /;/, $data;
  7. }
  8.  
That will split the line into its different sections, delimited by a semicolon. What you do with that from there is up to you.

Regards,

Jeff
Aug 1 '07 #2
KevinADC
4,059 Expert 2GB
Maybe all you need is to group the various patterns you want to split on using parenthesis:

@split_feature_protein_field = split ( /\s(Region|Site|Bond)/,$split_feature_protein_field1[1] ) ;

But really without any context to go by it is not possible to say why you believe it is not working.

Also, you are defining the array by splitting the array on the second element of the existing array. Any value the array @split_feature_protein_field had before the split will be lost and a new array will be created. This might not be what you want to do.
Aug 1 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Kylotan | last post by:
I have a text file where the fields are delimited in various different ways. For example, strings are terminated with a tilde, numbers are terminated with whitespace, and some identifiers are...
9
by: Sreejith S S Nair | last post by:
hi there, I have a panel control which contain more than 10 label controls. these label controls are added dynamically by user. In this application user can slit a control into not less than...
0
by: Sreejith S S Nair | last post by:
hi, Setp one. i have one panel control in my form. I am spliting this panel control into two part say working region and holding region. This spliting is only logic spliting. That is i...
33
by: Geometer | last post by:
Hello, and good whatever daytime is at your place.. please can somebody tell me, what the standard behavior of strtok shall be, if it encounters two or more consecutive delimiters like in...
1
by: vang | last post by:
How do I find out which delimiter if found/used when splitting a string with multiple delimiters are defined in a char array? Example: dim i as integer dim returnText as string dim InputText...
1
by: pencoder | last post by:
Actually i wrote C# codings to read text between delimiters.it works nicely. in my codings i have a condition it checks whether the delimiter indexed first time or the second time.based on that i...
1
by: gopiganguly | last post by:
Hi everyone, There is a small problem encountered while creating a package in sql server 2005. Actually i am using a flat file which has 820 rows and 2 columns which are seperated by line...
3
by: nuatpy | last post by:
I have a csv file that is mainly comma seperated, but one of the fields has currency values in the form "$1,378.59". By just specifying a delimiter:',' in my dialect, the above value gets parsed as...
0
by: PLALS | last post by:
Hi All, I am looking for the recursive function in C# for spliting the single row data into multiple row, I have a data table in C# and the table contents data like column --> :| A | B ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.