w********o 发帖数: 10088 | 1 有一个字符变量
$string="Today we have five fruits (apple, orange, mango, peach and pear)
and two desserts (cheese cake and ice cream cake) "
想从里面根据关键词 fruits和desserts判断,把那些水果,甜点的分别赋值给两个数组
@fruit=("apple", "orange", "mango", "peach", "pear")
@dessert=("cheese cake","ice cream cake")
请问这种有没有简洁的实现方式? | T*****e 发帖数: 361 | 2 $string =~ /fruits \((.*)\).*desserts\((.*)\)/;
@fruit = split /, | and /, $1;
@dessert = split / and /, $2; |
|