b4swine has asked for the wisdom of the Perl Monks concerning the following question:
There is no equivalent operator to force an expression to be interpolated in list context because in practice, this is never needed. If you really wanted to do so, however, you could use the construction @{[ (some expression) ]}, but usually a simple (some expression) suffices.I wanted to see if there are at least three a's in "baa baa black sheep", so I write:
This doesn't work, but obviously the @{[...]} strategy does work. Is there any simpler way?print (('baa baa black sheep' =~ /a/g) >= 3 ? 'more' : 'less');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Counting matches.
by ikegami (Patriarch) on Dec 07, 2007 at 08:06 UTC | |
by ikegami (Patriarch) on Dec 07, 2007 at 08:25 UTC | |
|
Re: Counting matches.
by poolpi (Hermit) on Dec 07, 2007 at 11:36 UTC | |
|
Re: Counting matches.
by sh1tn (Priest) on Dec 07, 2007 at 12:39 UTC |