in reply to Re: What should be returned in scalar context?
in thread What should be returned in scalar context?
I think that use of wantarray() to modify return behavior should be generally avoided. In my opinion it is a clear violation of the principal of least surprise.This obviously depends on what exactly is being returned in the first pace, but in general I agree. When you don't have any particular reason to think about context, don't use wantarray. I find that, often, the 'problem' solves itself without me thinking about it.
Having said that, I do use wantarry sometimes, and my reasons are usually effiency related:
Also, it seems like a better idea than just returning the last column, or the number of columns, or anything like that, which would likely be the result of not using wantarray in this case.
There might be better examples, but I'm too lazy to think of them now.
Joost.
-- #!/usr/bin/perl -w use strict;$;= ";Jtunsitr pa;ngo;t1h\$e;r. )p.e(r;ls ;h;a;c.k^e;rs ";$_=$;;do{$..=chop}while(chop);$_=$;;eval$.;
|
|---|