You are here: Foswiki>Tasks Web>Item202 (17 Nov 2008, OlivierRaginel)Edit Attach
As it seems silly and slow to always use:
my ($return, $code) = $sandbox->sysCommand( $cmd );

I suggest we simplify this:
my $return = $sandbox->sysCommand( $cmd );

If we don't need the return code, using wantarray we know we've been requested a scalar, so we simply send back the output.

If you disagree with this change, please let me know and I'll roll-back (and fix the few places where I've used it).

I've check the current usage of this, and it shouldn't break anything (all calls are either like above, or void.

-- OlivierRaginel - 16 Nov 2008 - 21:21

I'll take your word for it that it's faster, but the reason I personally avoid wantarray is code legibility. I found context dependencies like this hell to deal with when I was learning perl, and I don't really want to put other people in that position.

So, go ahead and make the change if it makes for better code, but comment it to death, please!

-- CrawfordCurrie - 17 Nov 2008 - 09:36

I got your points, and they make sense, a lot of sense.

I thought it was pretty obvious that wantarray had to be faster, because you're not building up the array, and then discarding some parts of it, but I got told otherwise by some perl mongers.

I'll revert my changes, and fix the 2 occurences where this was used.

For the record, I'll use:
my ( $return ) = $sandbox->sysCommand( $cmd );
return ( $sandbox->sysCommand( $cmd ) )[0];

-- OlivierRaginel - 17 Nov 2008 - 10:12

ItemTemplate edit

Summary Add wantarray to Sandbox->sysCommand
ReportedBy TWiki:Main.OlivierRaginel
Codebase nextwiki
SVN Range TWiki-4.2.3, Wed, 06 Aug 2008, build 17396
AppliesTo Engine
Component Sandbox
Priority Normal
CurrentState No Action Required
Checkins distro:f9f21f5f207d distro:ffe1fd2e7879 EmbedBibPlugin:81e3e67ff290
Topic revision: r6 - 17 Nov 2008, OlivierRaginel
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy