Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Toy singleton class
#perl 5.22.1 package Borg; #a crude implementation of the singleton pattern. sub new{my $init=sub{bless [], $_[0]}; my $cl=$_[0]; # &init does what new usually does eval "\$$cl\::{borg}//(\$$cl\::{borg}=&\$init)";} package main; $x=Borg->new; $y=Borg->new; $x->[0]=5; #now $y is also [5] print $y->[0]
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Riyali-101738
main_objetos
Perl
Hashes
Perl
2nd
Balancing brackets
Perl Lang
test321
perl circle plot
stackse - search stackoverflow differently
Please log in to post a comment.