ameezys has asked for the wisdom of the Perl Monks concerning the following question:

I tried to run this script but there's an error. Can someone explain what it means and how to fix it. Thankyou.

use Class::Struct; struct Person { name => '$', age => '$', peers => '@', }; my $p = Person->new(); $p->name("Jason Smythe"); $p->age(13); $p->peers( ["Wilbur", "Ralph", "Fred"] ) ; printf"At age %d, %s's first friend is %s.\n", $p->age, $p->name, $p-> +peers(0);

Replies are listed 'Best First'.
Re: Struct class
by GrandFather (Saint) on Apr 03, 2019 at 04:19 UTC

    You don't tell us what the error is. However, running the code give the error:

    Can't locate object method "Person" via package "name" (perhaps you fo +rgot to load "name"?) at ...

    so something like that is most likely what you are seeing. The issue is your use of the struct function. You need to write it like:

    struct Person => { name => '$', age => '$', peers => '@', };
    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond