in reply to A question of style

well, nothing to stop you returning a value rather than manipulating a global.
my $response = doSomething(); sub doSomething { return 0; }
updated I was being terribly inefficient there! Took out the code that created a lexical variable within the sub.

will do it, but remember also that Perl returns the last computed value form a sub as well. So:

my $response = doSomething(); sub doSomething { my $response = 0; }
works just as well.

My advice would be to explicitly return something from the sub rather than manipulating a variable which is outside the sub.

jdtoronto

Replies are listed 'Best First'.
Re: Re: A question of style
by pbeckingham (Parson) on Mar 30, 2004 at 17:47 UTC

    Did you intend to hide the definition of my $response at the outer scope? Why not just place a 0; at the last line of the sub, rather than create a lexical only to have it read and destroyed immediately?