in reply to Why use references?
1) because you may want to pass a scalar, a list and a hash to a subroutine. You can do that with:
testfunc($scalar,\@array,\%hash); sub testfunc { my ($scalar,$arrayref,$hashref) = @_; }
2) Because hash references are fundamental to OO perl.
3) (Elaborating chas a little) Because a data structure like:
my $appointments = { monday=> { "10:30"=>"dentist", "11:30"=>"doctor" }, tuesday => { "10:30" => " planning meeting", "16:30" => " funding deadline" } };
can be very useful.
4) Because once you start using array refs and hash refs, you'lll wonder how you ever managed without them.
I may be missing something, but I rarely have occasion to use a scalar ref in the simple $ref = \$var; form.
Update:Struck out 'hash' in 'hash references' at blazars suggestion - TIMTOWTDI.
--------------------------------------------------------------
"If there is such a phenomenon as absolute evil, it consists in treating another human being as a thing."
John Brunner, "The Shockwave Rider".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why use references?
by blazar (Canon) on Dec 12, 2005 at 14:42 UTC | |
|
Re^2: Why use references?
by w3b (Beadle) on Dec 12, 2005 at 12:15 UTC |