>===========================================
>sub func1 {
>my (%rez);
>
>    $rez{one} = 'one';
>    $rez{two} = 'two';
>    $rez{seven} = 'seven';
>
>    return %rez;
>}
>===========================================
>
>and I have such piece of code:
>
>===========================================
>%rez = func1;
>$val = $rez{two};
>
>print $val;
>===========================================
>
>I want to avoid using %rez in second piece of code, parse output of func1 in 
>one
>step.
>
>How?
>


Hello.The simple way is using a package variable (which is global in all your 
code) for your %rez.
For example,you could declare your variable as:

our %rez;

or

use vars qw/%rez/;

Then you could access the %rez anywhere in your code.

But,use an unnecessary variable outside its score is not good programming 
practice.I would suggest you return a hash ref instead of a hash in your 
subroutine,then the code is more clear.

sub func1 {
my (%rez);

    $rez{one} = 'one';
    $rez{two} = 'two';
   $rez{seven} = 'seven';

   return \%rez;
}

Then you could access the hash via its ref:

my $hash_ref = func1;
print $hash_ref->{one};

Hope this helps.



--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to