in reply to goto with some arguments

Surely that's just the same as:
if ($this_is_not_right) { goto_somewhere (error_code => 123, error_msg => 'this is error'); } do_something(); return; sub goto_somewhere { show_error_page(@_); exit; # ??? Or did you want to come back ??? }
Goto is ugly bad bad bad code.

Replies are listed 'Best First'.
Re: Re: goto with some arguments
by larsen (Parson) on Mar 16, 2003 at 23:52 UTC
    While it's probably true that unconditional jumps should be avoided, I'm not against goto "a priori". And, since we're talking about Perl's goto, a mention of the goto &NAME idiom is in order:
    use strict; use warnings; use vars qw/$AUTOLOAD/; sub AUTOLOAD { $AUTOLOAD =~ /.*::(.*)/; my $name = $1; print "It looks like you're trying to call $name...\n"; no strict 'refs'; *{ "main::$name" } = sub { print "Hey, I've been called by ", (caller)[0], ", and here my arguments: @_\n"; }; goto &{ "main::$name" }; # The brand new sub can't realize it has # been actually called from somewhere # else } foo( "Hello", "World" ); foo( "Howdy, world" ); # I call foo() again, this time it exists sub bar { foo( "See you, world" ); } bar();