Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Perl goto (was: static variable problem)

Received: by 10.66.88.200 with SMTP id bi8mr9551072pab.27.1352899429221;
        Wed, 14 Nov 2012 05:23:49 -0800 (PST)
Path: s9ni11067pbb.0!nntp.google.com!news.glorb.com!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: Rainer Weikusat <rweiku...@mssgmbh.com>
Newsgroups: comp.lang.perl.misc
Subject: Perl goto (was: static variable problem)
Date: Wed, 14 Nov 2012 13:23:46 +0000
Lines: 44
Message-ID: <87obj0pbbx.fsf_-_@sapphire.mobileactivedefense.com>
References: <fV45K0OBJxbE-pn2-l0DOsOblSoed@localhost> <3ca96274-d8ae-4d20-9ec4-d643ec5caae9@googlegroups.com>
Mime-Version: 1.0
X-Trace: individual.net ieyen5zQGr5/q8dIr/regAvOkgIY+hancTnGN1h0KoVcQjUcHAGRNSu3bBi6yRJHE=
Cancel-Lock: sha1:yNhGi33qi3Ps1WXlJs8OGdYeKr8= sha1:DAcXfJVMcYOy/RPyfUU72XCGVoE=
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)
Content-Type: text/plain; charset=us-ascii

"C.DeRykus" <dery...@gmail.com> writes:

[...]

>   goto BLOCK;
>
>   FOO: foo("Hello World");
>   exit;
>
>   BLOCK: {
>     my $bar = 1;
>
>     sub foo
>     {
>       my $a = shift;
>       print "$bar $a\n";   
>       return;
>     }
>     goto FOO;
> };

In contrast to 'other languages', the destination of a Perl goto is
determined at runtime, by 'outward' searching (IIRC, term used by the
Camel book) for a matching label in all currently active lexical
scopes. This implies that, compared to other means for performing flow
control, it is a very expensive operation.

--------------
use Benchmark;

timethese(-5,
	  {
	   goto => sub {
	       goto out;

	       print "ha!";

	       out:
	       return 3;
	   },

	   return => sub {
	       return 3;
	   }});