Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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?

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 taking refuge in the Monastery: (4)
As of 2014-09-20 19:34 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (160 votes), past polls