[source] exemplo diferença POO perl 5 e 6

Postagem de conteúdo sobre programação perl
Post Reply
User avatar
Kodo no Kami
Admin
Admin
Posts: 740
Joined: Fri Jan 02, 2015 1:56 pm
Contact:

[source] exemplo diferença POO perl 5 e 6

Post by Kodo no Kami » Thu Mar 07, 2019 5:36 pm

POO perl5

Code: Select all

#!/usr/bin/perl

use v5;

$k = new Kodo;
$k->setValue(100);
print $k->getValue();

package Kodo;

sub new{
    $this = shift;
    $argu = {$valor => 0};
    return bless $argu,$this;
}

sub setValue{
    $this = shift;
    @argu = @_;
    $this->{valor} = $argu[0];
}

sub getValue{
    $this = shift;
    return $this->{valor};
}
POO perl6

Code: Select all

#!/usr/bin/perl6

use v6;

class Kodo{
    has $!valor;
    
    method setValue($val){
        $!valor = $val;
    }
    
    method getValue(){
        return $!valor;
    }    
}

my $k = Kodo.new;
$k.setValue(100);
say $k.getValue();
Image

que desagradavel ~ mirai kuriyama

shotp0c
Membro
Membro
Posts: 1
Joined: Wed May 23, 2018 10:41 pm

Re: [source] exemplo diferença POO perl 5 e 6

Post by shotp0c » Tue Mar 19, 2019 8:59 pm

Brabo!!!

Post Reply

Return to “Perl”