Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

split delimiters

by Anonymous Monk
on Mar 27, 2001 at 01:21 UTC ( #67334=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Although I have worked on Perl for a few months, I am quite the major rookie. I am working on a script where I need to split lines of a report into fields and I am having problems using ( and [ as delimiters. There is really no other way to split this and I have no clue what to do..can you help me please!!!!! My deadline is approaching?!??!??!?!?!

Replies are listed 'Best First'.
Re: split delimiters
by busunsl (Vicar) on Mar 27, 2001 at 01:26 UTC
    Since ( and [ are special characters in regular expressions, you have to escape them:
    split /\(/, 'some(odd(string'; split /\[/, 'next[odd[string';
      Or, just in case both of these delimiters should be used for one split...

      split /[\[\(]/, 'some(next[really(really(odd[string';
        Well, in that case you don't have to escape them, because they are in sqare brackets:
        split /[([]/, 'some(wierd[string';
Re: split delimiters
by myocom (Deacon) on Mar 27, 2001 at 01:24 UTC

    This would be infinitely easier if you were to post your script (make sure to enclose it in <code> tags!), some sample data, the expected output, and what you're getting now.

Re: split delimiters
by wardk (Deacon) on Mar 27, 2001 at 01:25 UTC

    there is going to be a number of ways to slay this dragon.

    Please provide a couple of data records as an example of the actual data, and if you have some, post the code that currently isn't making it happen for you...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://67334]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2020-09-22 22:09 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (130 votes). Check out past polls.