Janek Schleicher wrote: > Jimstone7 wrote at Thu, 27 Mar 2003 06:39:25 -0500: > > > $data = "David (man from uncle)"; > > > > $data = "John Doe (The boy down the hall)"; > > > > What I want to do is split $data into two string variables, one holding the > > $name, and the other holding all the $info that is within the parens. How > > would I do this? Thanks for any help. > > I would use a regexp: > > my ($name, $info) = $data =~ /(.*?)\w+\((.*)\)/;
Hi Janek. I'm afraid your regex is wrong! It does the following: capture zero or more (as few as possible) of any character !! match one or more 'word' characters followed by an open parenthesis capture zero or more (as many as possible) of any character match a close parenthesis It will fail on the given data since the second match never succeeds. The following will do the trick, splitting the string on either an open or close parenthesis. I hope this helps, Rob while ( <DATA> ) { my ($name, $info) = split /[()]/; print "$name\n$info\n\n"; } __DATA__ David (man from uncle) John Doe (The boy down the hall) output David man from uncle John Doe The boy down the hall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]