In Perl, it\'s often nice to be able to assign an object, but specify some fall-back value if the variable being assigned from is \'undef\'. For instance:
my $x
Just some nitpicking with your Perl example:
my $x = undef;
This redundant code can be shortened to:
my $x;
And the following code doesn't do what you say it does:
my $a = $x || $y;
This actually assigns $y to $a when $x is false. False values include things like undef, zero, and the empty string. To only test for definedness, you could do the following (as of Perl 5.10):
my $a = $x // $y;