Jeff, et al -- ...and then Jeff 'japhy' Pinyan said... % % On Aug 17, David T-G said: % % >% > 45 my $body = % >% > 46 &parseit ... % >% % >% First, you can drop the & on the function call. It's not necessary. % > % >Interesting. I thought it was a good thing for clarification. Not % >needed because I'm passing params, maybe? % % Ther 'perlsub' documentation sets the record straight. Basically, a '&'
Heh. As always. I should have looked there before opening my mouth! :-)
% is only needed...
%
% 1. when calling a user-defined function with the same name as a built-in
OK...
% 2. when taking a reference to a function
Ah.
% 3. to avoid the function's prototype
% 4. when used with goto &function to avoid another stack level
Still too rich for my blood :-)
% 5. in conjunction with no argument list, to pass the current @_
Ahhh... So that's probably why I would use it before.
%
...
% >All of that makes sense. I guess it can only follow for passing to a
% >function, eh?
%
% Exactly, since the arguments to a function are placed into an ordinary
% array (with a special name).
OK.
%
% >% sub parse_it {
% >% my ($tmpl, $user) = @_; # hash references are scalars
%
% >% my %template = %$tmpl; # remember, hashes slurp, so we couldn't
% >% my %userdata = %$user; # have done (%a, %b) = (%$c, %$d)
% >
% >Right; I can see that. So I still get a local %template that I could
% >change as I like without trashing the original. Yay.
%
% Very important thing you've noted. Yes, %template is just a COPY of the
Yep.
% hash stored in $tmpl. However, if any of the values in %$tmpl are
% references themselves, changing them in %template would change them in
% %$tmpl, because a "copy" of a reference is just the reference.
Oooh, good point. Hadn't even thought of that. So if $tmpl is a pointer
to a pointer, as an example, then it's the same thing anyway. Interesting...
%
% my $data = {
% name => [ "Jeffrey", "Pinyan" ],
% age => 21,
% };
You're kidding, right? *sigh* One of these days I'll remember that the
world is not simply either my age or my daughters'...
%
% my %copy = %$data;
% ++$copy{age}; # in november
% $copy{name}[0] = "Jeff"; # please, call me Jeff
%
% print "@{ $data->{name} } is $data->{age} years old\n";
% # "Jeff Pinyan is 21 years old"
%
% print "@{ $copy{name} } is $copy{age} years old\n";
% # "Jeff Pinyan is 22 years old"
Pretty sneak of you. Almost like being in two places at once :-)
%
% You can see from that example that, since 'age' is not a reference,
% changing it in %copy doesn't affect it in %$data. However, 'name' points
Yep.
% to an array reference, so $data->{name} and $copy{name} are really the
% same array reference. (Read more about this in perlref and the like.)
Gotcha.
Thanks a bunch & HAND
:-D
--
David T-G * There is too much animal courage in
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED] -- Mary Baker Eddy, "Science and Health"
http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!
pgp00000.pgp
Description: PGP signature
