in reply to assignment operator return values
Yes, that works as you expect. Assignments read from right to left, ie. $x = $y = $z = 10 assigns 10 to $z, then assigns the value of $z to $y, then the value of $y to $x – so all three variables end up with the value 10.
However, the code you want this for can be written cleaner without inline assignment:
sub path_to_root { my $self = shift; my $path = $self->get_branch_length; my $parent = $self->get_parent; while ( $parent ) { $path += $parent->get_branch_length; $parent = $parent->get_parent; } return $path; }
Makeshifts last the longest.
|
|---|