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

Hello monks.

Disclaimer: This is part of a course project although the instructor is giving us (her students) complete freedom in constructing our course projects.

I have decided to build an OO perl program, but I do not know how to include the ability to pass arguments to a method:

Something like the following:
$protein_strand->fold(-style => 'prion'); # *this is where I # am confused*

Would I simply include a shift within the method definition thereby storing the key and value of the hash? Any constructive suggestions would be most welcome.

Thanks Monks.

Replies are listed 'Best First'.
Re: Objected oriented perl with attributes in methods?
by choroba (Cardinal) on May 31, 2013 at 19:52 UTC
    The first argument passed to a method is the invocant. The "hash" is passed as a list, but you can copy it to a hash:
    sub fold { my $self = shift; my %options = @_; if ($options{-style} eq 'prion') { # ... } }
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Thanks choroba!

      I completely forgot that the '=>' is simply a comma and what I initially thought was a hash was actually a list.
      Thanks again for the help.
Re: Objected oriented perl with attributes in methods?
by jmlynesjr (Deacon) on Jun 01, 2013 at 16:22 UTC

    When in doubt about passed arguments,

    use Data::Dumper; print Dumper(@_);

    If software gets tired, my Dumper module is exhausted! :-)

    James

    There's never enough time to do it right, but always enough time to do it over...