From: Robert Klemme Date: 2007-10-17T15:05:04+09:00 Subject: Re: Compound conditionals in case when statements? Syntax? On 17.10.2007 03:46, Peņa wrote: > From: Randy Kramer [mailto:rhkramer@gmail.com] > # Subject: Compound conditionals in case when statements? Syntax? > # > # I need (or want ;-) to do something like the following: > # when ((/^---\+\+ (.*)/) and (new_record == true)) > > cases come in two forms, > > 1 classic switch form, like > > case sw > when foo > #.. > when bar > #.. > else > #.. > end > > this form is interpreted using if is like (as already explained by mentalguy), > > if foo===sw > #.. > elsif bar===sw > #.. > else > #.. > end > > > 2 conditional form (similar to nested ifs), like > > case > when foo > #... > when bar and condition1 > #... > when condition2 or condition3 > #.. > else > #.. > end > > this form is interpreted using if like, > > if foo > #.. > elsif bar and condition1 > #.. > elsif condition2 or condition3 > #.. > else > #.. > end > > I would reckon fr your post that you may want the second form. So something like, > > case > when ((/^---\+\+ (.*)/) and new_record > #.. > end Maybe rather: case when new_record && /^---\+\+ / =~ s Note the matching operator, otherwise $_ will be matched. Note also, that it is superfluous to match the rest of the string unless the content need to be further processed. I'd probably also reverse the order since I assume new_record is a local variable and that test is likely faster than the regexp matching. Kind regards robert