generic function replace<T>(var X: T; NewValue: T):T;
begin
Result := X;
X := NewValue;
end;
begin
x := someoldvalue;
y := specialize replace<TSomeType>(x, somenewvalue);
end.
no strict 'vars';
($old,$x) = ($x, $new);
This works in the default mode of no strict 'vars' where variables need not be pre-declared. See the other implementation for the more normal case where the use strict pragma is in effect.
use strict;
my $old;
my $new = 'new thing';
my $x = 'old thing';
($old,$x) = ($x, $new);
When use strict is in effect, variables must be predeclared.
generic function replace<T>(var X: T; NewValue: T):T;
begin
Result := X;
X := NewValue;
end;
begin
x := someoldvalue;
y := specialize replace<TSomeType>(x, somenewvalue);
end.