programming-examples/perl/Subroutine/Return reference to variable.pl
2019-11-15 12:59:38 +01:00

17 lines
329 B
Perl

#!/usr/bin/perl
use warnings;
use strict;
sub definelexical {
my $lexvar = "the original value";
return \$lexvar;
}
sub printlexicalref {
my $lexvar = ${$_[0]}; # dereference the reference
print "The variable still contains $lexvar \n";
}
my $ref = definelexical();
printlexicalref($ref);