Hi,

I'm searching for a part of wisdom, that I was not able to find in the Internet. So it is to good hidden for me;-)

So what I'm trying to build is a perl module that does a lot of work for various perl scripts for me. However there is one little kind of code (a simple parser), that has to be provided by the calling script. So I have code like this inside the script as parser...

sub parseGroupDescription { my $groupObj=shift; # my problem $groupObj is always undef / $g +roupObj is Net::LDAP:Entry my $groupName=get_attribute($groupObj,"erldapservicegroup"); my $groupDesc=get_attribute($groupObj,"description"); my $response; $response->{"name"}=$groupName; return $response; } # sub parseGroupDescription
I'm calling the method inside my main script using
my $data=$zbdbObj->fetchData($ldapConn,$serviceFilter,$groupFilter,sub + {parseGroupDescription});
The perl module has code like
sub fetchData { my $selfObj=shift; my $ldapConn=shift; my $serviceFilter=shift; my $groupFilter=shift; my $parseFunction=shift; ... foreach my $group ($allGroups->entries) { print get_attribute($group,"erldapservicegroup")." "; my $response=&$parseFunction->($group); # $group is a Net:: +LDAP:Entry object and $parseFunction a reference on the function of t +he main script my $groupName=$response->{"name"}; $serviceDataObj->{"groups"}->{$groupName}=$groupName; } # foreach my $group ($allGroups->entries) } # sub fetchData

I could see that my parser is called within this construct, however I was not able to find a way to pass the value of $groupObj to the parser.

Any ideas?

Regards

Oliver

PS: This is a simplyfied version of my code

In reply to Problems Passing an object to a function that was passed to a module by Oliver.Doerr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.