Jan, Thanks :-> The last blurb about the begin statement is what did the trick on the unix side, but now I'm getting errors on the windows side.
Here is what the functions now look like: # 1 # 2 # wrapper to lookup groups against local system configs via getent stuff 3 # - this module was adapted from the following code: 4 # http://techtasks.com/code/viewbookcode/1621 5 # 6 sub ResolveGroupsViaWin32 { 7 my ( $Logger , $Group ) = @_; 8 my @GroupMembers; 9 my %dicSeenGroupMember; 10 $Logger->debug("Entered into sub ResolveGroupsViaWin32"); 11 return unless $^O eq "MSWin32"; 12 require Win32::OLE; 13 Win32::OLE->import('in'); 14 my @GroupMembers = ResolveWin32Members("LDAP://$Group" , %dicSeenGroupMember , @GroupMembers ); 15 return @GroupMembers; 16 } # end ResolveGroupsViaWin32 17 # 18 # wrapper to lookup groups against the Win32::OLE module 19 # - this module was adapted from the following code: 20 # http://techtasks.com/code/viewbookcode/1621 21 # - BUG: Logger is not functioning properly - why not? 22 # 23 sub ResolveWin32Members { 24 my ($strGroupADsPath , %dicSeenGroupMember , @GroupMembers ) = @_; 25 my $objGroup = Win32::OLE->GetObject($strGroupADsPath) || return 1; 26 foreach my $objMember (in $objGroup->Members) { 27 push @GroupMembers, ,$objMember->sAMAccountName; 28 if ($objMember->Class eq "group") { 29 if (!$dicSeenGroupMember{$objMember->ADsPath}) { 30 $dicSeenGroupMember{$objMember->ADsPath} = 1; 31 ResolveWin32Members($objMember->ADsPath, %dicSeenGroupMember , @GroupMembers); 32 } 33 } 34 } 35 return @GroupMembers; 36 } # end DisplayMembers Windows error: D:\foo>perl -T foo.pl -x foo.xml Can't call method "Members" without a package or object reference at foo.pl line 187. If I change the import line to an or die it dies. I'm going to play with it a little more - any input would be appreciated. Thanks, Bill Jan Dubois wrote: > On Fri, 25 May 2007, Bill Schwanitz wrote: >> I am writing a perl script which I want to have platform independent. >> >> The over-all scope of the script is to pull in an xml doc, parse it and >> do group membership lookups against a variety of back-end systems. I >> have currently coded ( and gotten working ) standard unix getent and >> lookups against windows via Win32::Ole. >> >> I am trying to change the use to a require: >> >> sub ResolveViaWin32 { >> (...) >> BEGIN { >> require Win32::OLE or die "failed to require Win32::OLE: $!\n"; >> import Win32::OLE 'in' or die "failed to import in: $!\n"; >> } >> (...) >> } >> >> The require works, the import fails. My use ( use Win32::OLE 'in'; ) >> works great. >> >> Is there another way to accomplish this which I have just not found yet? > > I suspect something with indirect object syntax going wrong. Did you > try: > > Win32::OLE->import('in') or die; > > Alternatively you could get rid of the import() call and always call > Win32::OLE::in() explicitly, though that is slightly ugly. > > However, using a BEGIN block inside a function doesn't make a lot of sense, > as the block is evaluated at compile time, and the import will not be > lexically scoped to the function. I would put the BEGIN block at file level, > together with the rest of your "use" statements: > > BEGIN { > return unless $^O eq "MSWin32"; > require Win32::OLE; > Win32::OLE->import('in'); > } > > Cheers, > -Jan > -- Bill Schwanitz An eye for an eye makes the whole world blind. - Mahatma Gandhi
begin:vcard fn:Bill Schwanitz n:Bill;Schwanitz email;internet:[EMAIL PROTECTED] x-mozilla-html:FALSE url:http://http;//bilsch.org version:2.1 end:vcard
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Perl-Win32-Admin mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
