Circular References in Perl


A circular reference in Perl occurs when two references contain a reference to each other. You have to be careful while creating references otherwise a circular reference can lead to memory leaks. Following is an example −

Example

 Live Demo

#!/usr/bin/perl
my $foo = 100;
$foo = \$foo;
print "Value of foo is : ", $$foo, "\n";

Output

When the above program is executed, it produces the following result −

Value of foo is : REF(0x9aae38)

Updated on: 29-Nov-2019

227 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements