in reply to Re: pointer memory and dynamic memory
in thread pointer memory and dynamic memory
And when you say, why would you want a reference to a hash or array element, when you can just say $x{key} or $y[$index]? I'd answer, one reason is that you may be dealing with something expects a reference to a scalar.use strict; my $x = {}; $x->{a}->{b}->{c}->{d} = 'watermelon'; print $x->{a}->{b}->{c}->{d} , " is quite delicious\n"; my $ref = \ $x->{a}->{b}->{c}->{d}; $$ref = 'cantelope'; print $x->{a}->{b}->{c}->{d} , " is quite delicious\n";
For example, think about implementing a toy spreadsheet in Tk. (Scary thought!) A reasonable data structure for a toy implementation would be an LOL of scalars, with references to each array element bound into a TK widget for display and updating. You'd need refs to every cell because (in this case) Tk wants refs.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: pointer memory and dynamic memory
by BrowserUk (Patriarch) on Oct 14, 2004 at 07:31 UTC |