Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

split delimiters

by Anonymous Monk
on Mar 27, 2001 at 01:21 UTC ( [id://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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found