On Fri, 2 Sep 2005, Luinrandir wrote:

> Can I pass a hash to a package?

Yes.

(Hint: passing any complex data around is generally best done with the 
use of references, so that's the area you need to be studying up on.)

Pseudocode:

  my $result = go_do_something_with( \%this_hash );

  ...

  sub go_do_something_with {
      my $hashref = shift;
      ...
      return $result;
   }

You just have to get the hash data back out of $hashref this way. 

If you need to pass multiple hashes, the same idea applies:

  my $new_result = act_upon( \%hash_a, \%hash_b, \%hash_c );

  ...

  sub act_upon {
    my ( $a_ref, $b_ref, $c_ref ) = @_;
    ...
    return $result;
  }

And, again, you just need to unpack $a_ref, $b_ref, and $c_ref in 
exactly the same way you unpacked $hashref in the first example.

If you need to pass more complex data structures, this is the general 
approach to doing so that most people seem to use. 



-- 
Chris Devers

›¯)làwÓ›î¬ 
-- 
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