in reply to What should be returned in scalar context?
As an example, consider this real-world case from Bricolage:
@stories = Bric::Biz::Asset::Business::Story->list(); if (not @stories) { print "There are no stories.\n"; }
That works fine, but this doesn't:
if (not Bric::Biz::Asset::Business::Story->list()) { print "There are no stories.\n"; }
That's because Bricolage list() methods (and lots of other Bricolage methods) try to be helpful and return array refs in scalar context. I've personally found a number of bugs that turned out to be caused by this problem, and I'm sure there are more waiting to be found.
There may be cases where wantarray() is useful, but I definitely don't consider it a general-purpose tool.
-sam
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: What should be returned in scalar context?
by Joost (Canon) on Dec 03, 2003 at 20:22 UTC |