0

我有这个结构

package StrukturaStudent;
use Class::Struct;

struct Student => {
sifra => '$',
ime => '$',  
prezime => '$',
brojBodova => '$'
};

和功能

sub ispisiStudenta($st){
print $st->{sifra}." ". $st->{ime}." ". $st->{rezime}." ". $st->{brojBodova}."\n";
}

我想在其中打印当前学生。

In another package I have an array of students and call this function as

StrukturaStudent->ispisiStudenta(@lista[1])."\n";

I don't get anything (only new empty line on console). But when I call this from main

print @lista[1]->ime;

I got right what I need. So how to pass a single student from the array and print it inside function? Moreover, how can I pass the whole array and print every student in it inside a for loop?

4

1 回答 1

4

$st->{ime}不一样$st->ime。第一个在哈希引用中搜索键,第二个调用方法。

您应该始终使用带有 Class:Struct 的方法,如文档中所示。此外,您不能在 Perl 中声明命名参数:

sub ispisiStudenta {
    my $st = shift;
    print join(' ', $st->sifra, $st->ime, $st->rezime, $st->brojBodova), "\n";
}
于 2013-04-08T10:43:06.123 回答