Petr Vileta wrote:

: I have public hash and in sub{}

    A public hash sounds like a really bad idea. Why not use a
lexically scoped hash and specifically pass it into the sub?


: Example with success but maybe is possible to write it better:
:
: our $hash;
: $hash->{first} = 1;
: $hash->{second} = 2;
: &mysub;
: print $hash->{second};
:
: sub mysub {
:     my $new_hash;
:     # make local copy
:     $new_hash->{$_} = $hash->{$_} foreach (keys %{$hash});
:     print $new_hash->{second};
:     $new_hash->{second} = 10;
:     print $new_hash->{second};
: }


my $hash = {
    first   => 1,
    second  => 2,
};

mysub( $hash );

print $hash->{second};

sub mysub {
    my %copy = %{ shift @_ };

    print $copy{second};
    $copy{second} = 10;
    print $copy{second};
}

__END__


: (My server reject all messages from Yahoo and Hotmail. Send me
: your mail from another non-spammer site please.)

    Replace "reject" with "rejects"


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don't tread on my bandwidth. Trim your posts.

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to