Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update perlref.pod to warn $f{B} = $f{A} is only copying a pointer #22036

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pod/perlref.pod
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ brackets:
'Clyde' => 'Bonnie',
};

But be aware:

$folks{A} = {
'Adam' => 'Eve',
'Clyde' => 'Bonnie',
};
$folks{B} = $folks{A}; # just pointers to the anonymous hash
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a reference, not a pointer.

%{ $folks{C} } = %{ $folks{A} }; # deep copy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a shallow copy, not a deep copy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's great you folks could put something better into that page than my version.

I even had my first accident today hitting the resolve button.

$folks{A}{Clyde} = 'Wilma'; # also updates B! C is immune
jidanni marked this conversation as resolved.
Show resolved Hide resolved

Anonymous hash and array composers like these can be intermixed freely to
produce as complicated a structure as you want. The multidimensional
syntax described below works for these too. The values above are
Expand Down
Loading