Have been browsing the Camel book and others and I
think I'm a little confused regarding the concept of
passing array & hash references to subroutines.

As far as I understand (and please please correct me
if I'm wrong) you pass array and hash references to
subroutines so that you don't have multiple copies of
the same array (or hash).  This example would be bad
because of what I just described:

sub foo {
   my @this_array = ( "one", "two", "three" );

   bar ( @this_array );
}

sub bar {
   my @that_array = @_;
}

So I'd pass a reference instead:

sub foo {
   my @this_array = ( "one", "two", "three" );

   bar ( \@this_array );
}

sub bar {
   my $that_array = @_;

   foreach @$that_array {
      # do stuff...
   }
}

Again, as I understand it the same applies to hashes
as well but I'm more confused about hashes than I am
about arrays.  How do I de-reference the
hash-reference so that I can use it in my subroutine -
similar to the @$that_array example used above (but
for hashes instead).

Hopefully my question makes sense.  Thanks in advance
of your help.

Jon Williams.



__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to