in reply to calling sub with object as param

Welcome to the Monastery!

You're creating an object prior to the sub call with a hash reference parameter, which has a key named attribute.

In the Operations package, you're trying to call attribute as a method (subroutine), but that's not what attribute is.

Change this:

$preparedStatement->execute($inputData->attribute)

...to this (note the curly braces around attribute, which denotes it as a hash reference key):

$preparedStatement->execute($inputData->{attribute})

and see if that helps get you where you want to be.

-stevieb

Replies are listed 'Best First'.
Re^2: calling sub with object as param
by Anonymous Monk on Sep 01, 2015 at 22:39 UTC

    I think the OP isn't handling the class name as the first parameter in the method.

      hello, thank you for your quick response , can you please give some sample code so that i can better understand what you mean ? i am just starting to learn perl.

        Hello perlnewb4life, and welcome to the Monastery!

        Anonymous Monk means that this:

        sub querryDatabase() { my($inputData) = @_; ...

        should be this:

        sub querryDatabase() { my($self, $inputData) = @_; ...

        because the first argument passed in to any method call is always an object reference. Here’s a contrived (and naïve) example:

        use strict; use warnings; package Widget { use Moose; has 'ID' => ( is => 'rw', isa => 'Str', required => 1, ); sub inc_id { my ($self, $inc) = @_; my $id = $self->ID; my ($prefix, $suffix) = $id =~ /^([^\d]+)(\d+)$/; $self->ID( $prefix . ($suffix + $inc) ); } } my $gizmo = Widget->new( { ID => 'PM142' } ); print $gizmo->ID, "\n"; $gizmo->inc_id(5); print $gizmo->ID, "\n";

        Output:

        16:41 >perl 1366_SoPW.pl PM142 PM147 16:41 >

        Note that the inc_id method receives two arguments, although only the second (in this case, 5) is passed explicitly in the method call $gizmo->inc_id(5). The first argument, a reference to the $gizmo object, is passed implicitly.

        Hope that helps,

        Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,