Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:
As you might expect, this creates an infinite loop. I wondered what might happen if $place were a tied variable that instead of fetching a value - did a goto elsewhere. Would the original goto ever get called?#!/usr/bin/perl use strict; use warnings; sub jump { my $place = 'START'; goto $place; } START: print "Hello, world\n"; jump();
This dies yelling about Can't find label END at ... First, I know that Perl supports goto label out of a sub as demonstrated by the first snippet. Second, I can't find anything in goto docs that would suggest this shouldn't work. Can anyone shed some light?#!/usr/bin/perl use strict; use warnings; sub jump { tie my $place, 'main'; goto $place; } START: print "Hello, world\n"; jump(); print "I am jumping over this spot\n"; END: print "Goodbye, cruel world\n"; sub TIESCALAR { bless {}, $_[0] } sub STORE { print "Read only\n"; } sub FETCH { goto END; }
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mixing tied variables with goto label
by dave_the_m (Monsignor) on Nov 16, 2005 at 00:27 UTC | |
by Limbic~Region (Chancellor) on Nov 16, 2005 at 00:50 UTC | |
by Steve_p (Priest) on Nov 16, 2005 at 21:07 UTC | |
by dave_the_m (Monsignor) on Nov 16, 2005 at 22:02 UTC | |
|
Re: Mixing tied variables with goto label
by jeffa (Bishop) on Nov 15, 2005 at 21:32 UTC | |
by Limbic~Region (Chancellor) on Nov 16, 2005 at 00:07 UTC |