Howdy group,
If you have a function that returns different things based on if they want an array or not how can you force print to be in scalr context?
for instance:
sub fooyou { my $header = 'whatever'; my $data1 = 'data1'; my $data2 = 'data2'; return ("$header$data1","$header$data2") if wantarray; return "$header$data1$data2"; }
do they can do
my ($d1,$d2) = fooyou();
if they want to have them seperate and each one has th header with i since it needs it. but if they will be together the same header will work so
my $alldata = fooyou();
is ok too..\
The problem is:
print fooyou();
I'd like for users to be able to just do that and have it do the second return (IE the scalar context one)
So is there a way I can tell inside my sub its being called by print do I can return what i want to print?
Perhaps this simplifies it also: How do you modify fooyou() below to get it to print 2 instead of 1 ? perl -mstrict -we 'sub fooyou { wantarray ? (1) : 2; } print fooyou();'
Thanks
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>