> If anyone has the time and / or the will to help me understand. > > I know how to create / use references for perl. But would why would you > use it. > And I think more importantly when. > > Im busy reading / learning the Oreilly Advanced Perl Programming book. > But for the likes of me I cant undertand when or why I would use it. >
I will give you one simple example. There are many other uses too :-) Suppose you want to pass two hashes as arguments to a subroutine. &sub_hash(%hash1, %hash2); ## You would expect the hashes to capture like the following.. sub sub_hash{ my (%hash1, %hash2) = @_; ... } But this is incorrect as the arguments will be passed as list and the hashes that you will try to capture would be lost. So here references come to the rescue. Pass the hashes as references. &sub_hash(\%hash1, \%hash2); sub sub_hash{ my ($rhash1, $rhash2) = @_; #$rhash1 would be a reference to %hash1... etc.. ##You can dereference the hashes like this... foreach my $key ( keys %{$hash1} ){ ....... As you are reading Advanced Perl Programming book, I hope you would find more examples on how to reference and dereference hashes. --Ankur -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>