in reply to Re^2: Error with using structs as subroutine parameters
in thread Error with using structs as subroutine parameters
Here's an example that hopefully clears up the usage:
use strict; use warnings; use Class::Struct; struct ( 'Structname', { value1 => '$', value2 => '$' } ); sub myfunction { my $mystruct = shift; # alternatively: my $mystruct = $_[0]; return $mystruct->value1." ".$mystruct->value2; } my $mystruct = new Structname; $mystruct->value1('foo'); $mystruct->value2(42); my $value = myfunction($mystruct); print "$value\n"; # "foo 42"
(This also works if you put the sub in a separate file that you then require.)
|
|---|