Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] perl hashes




> Passing a hash to a subroutine is just a matter of treating it as a
> scalar isn't it?

The hash itself can't be passed as a scalar, but you *can* pass a
reference to the hash:

  my( %foo ) = ( );

  &bar( \%foo );

Then you have to de-reference it on the other end:

  sub bar
  {
    my( $foo ) = @example.com;

    ... $$foo{ 'key' } ...

    ... keys( %{ $foo } ) ...

  }

Or, if you intend to do this a lot, you can define the hash as a scalar
reference in the 1st place:

  my( $foo ) = { };

  &bar( $foo );

and dereference the same way.

--
Joe Larabell -- Synopsys VCS Support      US: larabell@example.com
http://wwwin.synopsys.com/~larabell/   Japan: larabell@?jp


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links