Re: Perl Scope Question

2001-06-10 Thread iansmith
On Sun, 10 Jun 2001, Charles Lu wrote: > Variable "%hash" will not stay shared I forgot to mention a few little details.. so here is your example code with the corrections to get rid of the unsharing problem. use strict; my @list = ('apple',12, 'peach', 2, 'pear', 45); &function_one(@list);

Re: Perl Scope Question

2001-06-10 Thread Paul Dean
hya, On Mon, 11 Jun 2001, Charles Lu wrote: > > When I run the following code with the Warning flag I get the following > > message: > > > > Variable "%hash" will not stay shared > > > > Here is my code: > > > > #trying to sort a Hash by Value > > use strict; my($var, @list, %hash); sub fu

Re: Perl Scope Question

2001-06-10 Thread Karthik Krishnamurthy
with use strict and use warnings putting the hash outside function_one as a lexical or global both seem to work. Even making the hash inside function_one a global seems to generate a warning if use warning is in effect. so putting a function inside another seems to be no different from have it ou

Re: Perl Scope Question

2001-06-10 Thread iansmith
On Sun, 10 Jun 2001, Charles Lu wrote: > When I run the following code with the Warning flag I get the following > message: > > Variable "%hash" will not stay shared This can be a dangerous situation. Perl is complaining because of the nested subroutine. The dangerous part is that it that t

Re: Perl Scope Question

2001-06-10 Thread Karen Cravens
On 10 Jun 2001, at 23:37, Charles Lu wrote: >my @newhash = sort {$hash{$a} <=> $hash{$b}} keys %hash; It's not quite an answer to your question, but I'm curious why you nested the subroutine instead of just writing it like this? -- Karen J. Cravens ([EMAIL PROTECTED])

Perl Scope Question

2001-06-10 Thread Charles Lu
When I run the following code with the Warning flag I get the following message: Variable "%hash" will not stay shared Here is my code: #trying to sort a Hash by Value use strict; my @list = ('apple',12, 'peach', 2, 'pear', 45); &function_one(@list); sub function_one { my %hash = @_;