bless - place and plays in perl
WITHOUT BLESS WITH BLESS
package Class;
package Class; sub new { $classname = @_;
sub new { $classname = @_; $var = {};
$var= {}; bless($var, $classname);
return $var; } return $var; }
sub sample { print("TEST"); } sub sample{ print("TEST"); }
$var1 = Class->new(); $var1 = Class->new();
$o->sample(); $o->sample();
Output: Output:
Error TEST
Method 1:
sub new {
package Class;
package Class; sub new { $classname = @_;
sub new { $classname = @_; $var = {};
$var= {}; bless($var, $classname);
return $var; } return $var; }
sub sample { print("TEST"); } sub sample{ print("TEST"); }
$var1 = Class->new(); $var1 = Class->new();
$o->sample(); $o->sample();
Output: Output:
Error TEST
Method 1:
sub new {
$classvar = shift;
$selfref = {};
bless $selfref, $classvar;
}
Method 2:
sub new
{
$a={};
return bless $a;
}
Method 3:
sub new
{
$a={};
bless($a);
return $a;
}
Method 4:
sub new
{
$classvar = shift;
$a={};
bless($a,$classvar);
return $a;
}
Method 5:
sub new
{
$classname=shift;
$a={};
$a->{NAME}="apple";
bless $a,$classname;
}
Method 6:
sub new
{
$classname=shift;
$a=[];
$a->[0]=100;
bless $a,$classname;
return $a;
}
Method 7:
my $x = bless [], "packagename";
$x->functionname;
Method 8:
sub new {
classvar = $_[0];
my $var = $_[1]->{'name'};
my $this = {
'name' => $var,
};
bless($this, $classvar);
return $this;
}
Method 9:
$var1= "scalar";
$var2 = bless \$s, $classname;
return $var2;
Method 10:
my $obj = bless($ref, "Class");
sub bless {
my ($ref, $class) = @_;
$ref->{classname} = $class;
return $ref;
}
Method 11:
Method 2:
sub new
{
$a={};
return bless $a;
}
Method 3:
sub new
{
$a={};
bless($a);
return $a;
}
Method 4:
sub new
{
$classvar = shift;
$a={};
bless($a,$classvar);
return $a;
}
Method 5:
sub new
{
$classname=shift;
$a={};
$a->{NAME}="apple";
bless $a,$classname;
}
Method 6:
sub new
{
$classname=shift;
$a=[];
$a->[0]=100;
bless $a,$classname;
return $a;
}
Method 7:
my $x = bless [], "packagename";
$x->functionname;
Method 8:
sub new {
classvar = $_[0];
my $var = $_[1]->{'name'};
my $this = {
'name' => $var,
};
bless($this, $classvar);
return $this;
}
Method 9:
$var1= "scalar";
$var2 = bless \$s, $classname;
return $var2;
Method 10:
my $obj = bless($ref, "Class");
sub bless {
my ($ref, $class) = @_;
$ref->{classname} = $class;
return $ref;
}
Method 11:
sub new {
$classname = shift;
$self = [];
bless $self, $classname;
}
Method 12:
sub new
{
$a=[];
return bless $a;
}
Method 12:
sub new
{
$a=[];
return bless $a;
}
0 Comments:
Post a Comment
Note: only a member of this blog may post a comment.
<< Home