Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Passing a list as an arg to a subroutine

Reply
Thread Tools

Passing a list as an arg to a subroutine

 
 
Mark Drummond
Guest
Posts: n/a
 
      03-07-2006
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
 
Reply With Quote
 
 
 
 
Mark Drummond
Guest
Posts: n/a
 
      03-07-2006
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
 
Reply With Quote
 
 
 
 
Thomas Wasell
Guest
Posts: n/a
 
      03-09-2006
In article <>,
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"?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing ARG[0] parameters to a subroutine in a module dn.perl@gmail.com Perl Misc 3 03-21-2009 03:51 PM
How to pass a multiline arg to exec('some.exe arg')? n00m Python 5 05-05-2008 02:58 PM
use one subroutine's variable value in another subroutine inside a module. king Perl Misc 5 04-29-2007 06:39 AM
Trouble with setTimeout(arg, arg) nat.hourt@gmail.com Javascript 7 11-12-2005 05:13 PM
How to tell if a subroutine arg is a constant jonnytheclown Perl Misc 9 03-01-2005 01:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57