• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

saving words in variables

Hi all,
My question is if there is a sentence with words enclosed in brackets how to capture those words in and store them in different variables.

Example:
$sentence = "(((the dog)chased)the cat)";
now i have to save "the dog " in one variable, "chased" in another variable, "the cat" in another variable.

The sentence pattern will be same but may be of any long.Any suggestions will be appreciated.

Thanks.
0
cyberstud
Asked:
cyberstud
1 Solution
 
ozoCommented:
($one,$another,$variable) = $sentence =~ /([^()]+)/g;
0
 
cyberstudAuthor Commented:
But the sentence may be very long with many words in it.is there anyway to generate the variables in the LHS according to the words in RHS.In other words the sentence may change with more than three variables.How to deal with it....







0
 
renfieldCommented:
@words = ( $sentence =~ /([^()]+)/g );
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now