Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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?!??!??!?!?!

Comment on split delimiters
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...

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';

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2014-07-22 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (109 votes), past polls