From: Ian Jackson Subject: Re: [PATCH 2/7] vtpmmgr: add example control tools Date: Fri, 21 Mar 2014 11:57:30 +0000 Message-ID: <21292.10538.195671.78913@mariner.uk.xensource.com> References: <1395258759-24968-1-git-send-email-dgdegra@tycho.nsa.gov> <1395258759-24968-3-git-send-email-dgdegra@tycho.nsa.gov> <1395399526.27358.36.camel@kazak.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1395399526.27358.36.camel@kazak.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: Daniel De Graaf , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org Ian Campbell writes ("Re: [Xen-devel] [PATCH 2/7] vtpmmgr: add example control tools"): > On Wed, 2014-03-19 at 15:52 -0400, Daniel De Graaf wrote: > A trick I learnt from osstest.git:mg-hosts: > die unless @ARGV; > my $subcmd= shift @ARGV; > $subcmd =~ s/-/_/g; > my $subcmdproc; > { > $subcmdproc= \&{ "cmd_$subcmd" }; > } > $subcmdproc->(); > > (not sure what those braces do, Ian?) I think they were there to contain the scope of no strict qw(refs); which is mysteriously absent. ... So it turns out, on experimenting and RTFM, that "use strict" doesn't affect subroutine refs. So the braces are unnecessary. Also, since I wrote that I have been using a better idiom: my $funcn = $method; $funcn =~ y/-/_/; my $mainfunc = $main::{"main__$funcn"}; reject "unknown method" unless $mainfunc; #... &$mainfunc This makes it possible to print a sensible error message. Ian.