Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   Passing a list as an arg to a subroutine (http://www.velocityreviews.com/forums/t56369-passing-a-list-as-an-arg-to-a-subroutine.html)

Mark Drummond 03-07-2006 06:35 PM

Passing a list as an arg to a subroutine
 
Hi all. I've been using Perl for many years now, but I am a "use it and
learn it as you need it" type. I having some trouble passing a list to
the "search" subroutine from Net::LDAP.

I am trying to pass a list of attributes to be returned by search. The
basic method call is:

my $searchresults = $ldap->search(OPTIONS)

One of the options is "attrs =>" which the documentation describes as "A
list of attributes to be returned for each entry that matches the search
filter.".

I am able to do something like this no problem:

my $searchresults = $ldap->search (
base => "$searchbase",
filter => "$searchfilter",
attrs => [ 'uid', 'cn' ];
)

That works just fine.

But what I now want to do is provide the list of attributes to be
returned on the command line much like the way ldapsearch works. @ARGV
is the list of attributes to be returned. I am not sure how to pass
@ARGV to search. I've tried just passing the array, references to the
array, but nothing is working for me. The search completes, but, looking
at the directory logs, the search is requesting ALL attributes rather
than just the ones I want.

my $searchresults = $ldap->search (
base => "$searchbase",
filter => "$searchfilter",
attrs => @ARGV;
)

my $searchresults = $ldap->search (
base => "$searchbase",
filter => "$searchfilter",
attrs => \@ARGV;
)

I am sure I am just using a ref when I shouldn't be, or not using a ref
when I should, or simply referencing the array incorrectly but I am not
sure which one it is!

I actually have the same problem if I try to define the attributes
outside the subroutine call. e.g., if I do this:

my $attrs = [ 'cn', 'uid' ];
my $searchresults = $ldap->search (
base => "$searchbase",
filter => "$searchfilter",
attrs => $attrs;
)

That is not working for me either. Something is broken in my understanding.

Thanks,

Mark

Mark Drummond 03-07-2006 06:55 PM

Re: Passing a list as an arg to a subroutine
 
Cancel that, finally figured out what I was doing wrong. I was trying to
pass

"\@ARGV"

rather than

\ARGV

I was tripping over the "\" which of course has special meaning inside
the double quotes!

Mark

Thomas Wasell 03-09-2006 07:50 AM

Re: Passing a list as an arg to a subroutine
 
In article <CtqdnZQkpO8MSpDZnZ2dneKdnZydnZ2d@magma.ca>,
mark@gangwarily.ca wrote:
> Cancel that, finally figured out what I was doing wrong. I was trying to
> pass
>
> "\@ARGV"
>
> rather than
>
> \ARGV
>
> I was tripping over the "\" which of course has special meaning inside
> the double quotes!


And that's why you should ceck out

perldoc -q quoting
What's wrong with always quoting "$vars"?



All times are GMT. The time now is 03:47 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.