You are right. You can either assign the new list to the old one:
$head = $curr;
The old nodes will be freed, as there's no reference to the head remaining afterwards. Once the head is gone, the next node can be freed, too, and so on.
Or, you can use a bit more complicated procedure to invert the list in place:
$curr = $head;
my $tail;
while ($curr) {
my $next = $curr->{next};
$curr->{next} = $tail;
$tail = $curr;
$curr = $next;
}
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord
}map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|