Re: COMPLEX ARRAY STRUCTURE

2004-08-12 Thread Luis Daniel Lucio Quiroz
Thks,

Your first solution help me, I do a hash from anonymous array, then I modified 
and return to a anonymous array and ldapadd works well.

thsks.

LD

El Mar 10 Ago 2004 07:12, Ramprasad A Padmanabhan escribió:
> Luis Daniel Lucio Quiroz wrote:
> >You are wrong,
> >
> >I need some more flexible,
> >
> >I dont know what attributes will be added, that's why I need array be
> > coded on fly,with somthin like this
> >
> >$result = $ldap->add( 'cn=Barbara Jensen, o=University of Michigan,
> > c=US', attr =>$attrs);
> >
> >so $attrs array is formed on user commands
> >
> >:-P
> >
> >LD
>
> Luis, You still dont have to access the object directly.
> if $attrs is an object created from the users input , so be it.
>
> #Create a hash array of all user inputs. say
> %hash = get_user_input();
>
> # Have an array of all possible optional fields like
> @ALL_FIELDS =  qw ( mail l ou o .) ;
>
> # Create your attrs array
> $attrs = {};
> foreach (@ALL_FIELDS ) {
>if($hash{$_}) {
> $$attrs{$_}  = $hash{$_};   # Just make sure your input is trimmed
> for leading spaces  and lagging spaces or remove them here
>   }
> }
>
> # Now  add this to your ldap entries
>
> $result = $ldap->add( $dn, attr =>$attrs);
>
>
> IMHO that is simpler than poking at the structure and neater
>
> HTH
> Ram

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: COMPLEX ARRAY STRUCTURE

2004-08-10 Thread Ramprasad A Padmanabhan
Luis Daniel Lucio Quiroz wrote:
You are wrong,
I need some more flexible, 

I dont know what attributes will be added, that's why I need array be coded on 
fly,with somthin like this

$result = $ldap->add( 'cn=Barbara Jensen, o=University of Michigan,
c=US', attr =>$attrs);
so $attrs array is formed on user commands
:-P
LD
 

Luis, You still dont have to access the object directly. 
if $attrs is an object created from the users input , so be it.

#Create a hash array of all user inputs. say
%hash = get_user_input();
# Have an array of all possible optional fields like
@ALL_FIELDS =  qw ( mail l ou o .) ;
# Create your attrs array
$attrs = {};
foreach (@ALL_FIELDS ) {
  if($hash{$_}) {
   $$attrs{$_}  = $hash{$_};   # Just make sure your input is trimmed 
for leading spaces  and lagging spaces or remove them here
 }
}

# Now  add this to your ldap entries
$result = $ldap->add( $dn, attr =>$attrs);
IMHO that is simpler than poking at the structure and neater
HTH
Ram

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: COMPLEX ARRAY STRUCTURE

2004-08-09 Thread Chris Devers
On Mon, 9 Aug 2004, Luis Daniel Lucio Quiroz wrote:
You are wrong,
I see.
Good luck figuring it out then!

--
Chris Devers
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: COMPLEX ARRAY STRUCTURE

2004-08-09 Thread Luis Daniel Lucio Quiroz
You are wrong,

I need some more flexible, 

I dont know what attributes will be added, that's why I need array be coded on 
fly,with somthin like this

$result = $ldap->add( 'cn=Barbara Jensen, o=University of Michigan,
 c=US', attr =>$attrs);

so $attrs array is formed on user commands

:-P

LD

El Lun 09 Ago 2004 10:35, Chris Devers escribió:
> On Mon, 9 Aug 2004, Luis Daniel Lucio Quiroz wrote:
> > Yes I do,  I need array not to be hard-coded
>
> So don't hard-code it then.
>
> Just modify the update command the library provides so that it does what
> you need it to do.
>
> Manually poking at the data structure that a library uses internally is
> a BAD idea; it breaks the whole point of using object-oriented methods.
>
> So. You want to change how you do an update. So take this --
>
> >>  $result = $ldap->add( 'cn=Barbara Jensen, o=University of Michigan,
> >> c=US', attr => [ 'cn'   => ['Barbara Jensen', 'Barbs Jensen'], 'sn'   =>
> >> 'Jensen',
> >>  'mail' => '[EMAIL PROTECTED]',
> >>  'objectclass' => ['top', 'person',
> >>'organizationalPerson',
> >>'inetOrgPerson' ],
> >>]
> >>  );
> >>
> >>  $result->code && warn "failed to add entry: ", $result->error ;
>
> And edit the fields you need to have added.
>
>$result = $ldap->add(
>'cn'   => ['George Kaplan', 'Roger Thornhill'],
>'mail' => '[EMAIL PROTECTED]'
>);
>$result->code && warn "failed to add entry: ", $result-error;
>
>$result = $ldap->add( 'cn' => ["$name", "$nick"], 'mail' => "$mail" );
>$result->code && warn "failed to add $name/$mail: ", $result-error;
>
> In what way isn't this working for you?
>
>
> If you try to poke at the data structure Net::LDAP is using without
> going through the $ldap->add() method provided, you're probably going to
> regret it in the long run, when -- as inevitably happens -- some random
> update changes how things are stored but not the API and your code that
> depended on the old storage mechanism falls apart with the new one. If
> on the other hand you just use the normal API, you should be safe.
>
>
>
> --
> Chris Devers

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: COMPLEX ARRAY STRUCTURE

2004-08-09 Thread Chris Devers
On Mon, 9 Aug 2004, Luis Daniel Lucio Quiroz wrote:
Yes I do,  I need array not to be hard-coded
So don't hard-code it then.
Just modify the update command the library provides so that it does what 
you need it to do.

Manually poking at the data structure that a library uses internally is 
a BAD idea; it breaks the whole point of using object-oriented methods.

So. You want to change how you do an update. So take this --
 $result = $ldap->add( 'cn=Barbara Jensen, o=University of Michigan, c=US', attr 
=> [
 'cn'   => ['Barbara Jensen', 'Barbs Jensen'],
 'sn'   => 'Jensen',
 'mail' => '[EMAIL PROTECTED]',
 'objectclass' => ['top', 'person',
   'organizationalPerson',
   'inetOrgPerson' ],
   ]
 );
 $result->code && warn "failed to add entry: ", $result->error ;
And edit the fields you need to have added.
  $result = $ldap->add(
  'cn'   => ['George Kaplan', 'Roger Thornhill'],
  'mail' => '[EMAIL PROTECTED]'
  );
  $result->code && warn "failed to add entry: ", $result-error;
  $result = $ldap->add( 'cn' => ["$name", "$nick"], 'mail' => "$mail" );
  $result->code && warn "failed to add $name/$mail: ", $result-error;
In what way isn't this working for you?
If you try to poke at the data structure Net::LDAP is using without 
going through the $ldap->add() method provided, you're probably going to 
regret it in the long run, when -- as inevitably happens -- some random 
update changes how things are stored but not the API and your code that 
depended on the old storage mechanism falls apart with the new one. If 
on the other hand you just use the normal API, you should be safe.


--
Chris Devers
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: COMPLEX ARRAY STRUCTURE

2004-08-09 Thread Luis Daniel Lucio Quiroz
Yes I do,  I need array not to be hard-coded 

El Lun 09 Ago 2004 10:05, Chris Devers escribió:
> On Mon, 9 Aug 2004, Luis Daniel Lucio Quiroz wrote:
> > And Ramprasad is write, it's a LDAP-Perl scructure.  I need to
> > construct this structure on fly when executin a script.  So I wish
> > first how to access.
> >
> > So, lets tell  I want to add another element.
> >
> > After doing:
> > my %hash = @{$a};
>
> Did you try a `perldoc Net::LDAP` yet?
>
>SYNOPSIS
>  use Net::LDAP;
>
>  $ldap = Net::LDAP->new( 'ldap.bigfoot.com' ) or die "$@";
>
>  $mesg = $ldap->bind ;# an anonymous bind
>
>  $mesg = $ldap->search( # perform a search
> base   => "c=US",
> filter => "(&(sn=Barr) (o=Texas Instruments))"
>   );
>
>  $mesg->code && die $mesg->error;
>
>  foreach $entry ($mesg->entries) { $entry->dump; }
>
>  $mesg = $ldap->unbind;   # take down session
>
>  $ldap = Net::LDAP->new( 'ldap.umich.edu' );
>
>  # bind to a directory with dn and password
>  $mesg = $ldap->bind( 'cn=root, o=University of Michigan, c=us',
>   password => 'secret'
> );
>
>  $result = $ldap->add( 'cn=Barbara Jensen, o=University of Michigan,
> c=US', attr => [
>  'cn'   => ['Barbara Jensen', 'Barbs Jensen'],
>  'sn'   => 'Jensen',
>  'mail' => '[EMAIL PROTECTED]',
>  'objectclass' => ['top', 'person',
>'organizationalPerson',
>'inetOrgPerson' ],
>]
>  );
>
>  $result->code && warn "failed to add entry: ", $result->error ;
>  $mesg = $ldap->unbind;  # take down session
>
> Can you not add an entry this way?
>
>
>
> --
> Chris Devers

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: COMPLEX ARRAY STRUCTURE

2004-08-09 Thread Chris Devers
On Mon, 9 Aug 2004, Luis Daniel Lucio Quiroz wrote:
And Ramprasad is write, it's a LDAP-Perl scructure.  I need to 
construct this structure on fly when executin a script.  So I wish 
first how to access.

So, lets tell  I want to add another element.
After doing:
my %hash = @{$a};
Did you try a `perldoc Net::LDAP` yet?
  SYNOPSIS
use Net::LDAP;
$ldap = Net::LDAP->new( 'ldap.bigfoot.com' ) or die "$@";
$mesg = $ldap->bind ;# an anonymous bind
$mesg = $ldap->search( # perform a search
   base   => "c=US",
   filter => "(&(sn=Barr) (o=Texas Instruments))"
 );
$mesg->code && die $mesg->error;
foreach $entry ($mesg->entries) { $entry->dump; }
$mesg = $ldap->unbind;   # take down session
$ldap = Net::LDAP->new( 'ldap.umich.edu' );
# bind to a directory with dn and password
$mesg = $ldap->bind( 'cn=root, o=University of Michigan, c=us',
 password => 'secret'
   );
$result = $ldap->add( 'cn=Barbara Jensen, o=University of Michigan, c=US',
  attr => [
'cn'   => ['Barbara Jensen', 'Barbs Jensen'],
'sn'   => 'Jensen',
'mail' => '[EMAIL PROTECTED]',
'objectclass' => ['top', 'person',
  'organizationalPerson',
  'inetOrgPerson' ],
  ]
);
$result->code && warn "failed to add entry: ", $result->error ;
$mesg = $ldap->unbind;  # take down session
Can you not add an entry this way?

--
Chris Devers
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: COMPLEX ARRAY STRUCTURE

2004-08-09 Thread Luis Daniel Lucio Quiroz
yes, I'm pretty sure.  


And  Ramprasad is write, it's a LDAP-Perl scructure.   I need to construct 
this structure on fly when executin a script.  So I wish first how to access.

So, lets tell  I want to add another element.

After doing: 
my %hash = @{$a};

I do:   $hash{'initials'} = "S"; ???

If I heed an array shoul I do: $hash{'telephone'}=['',''];

and because it's a anonymous reference $a var is update automatly?

Merci beacoupe

LD

El Lun 09 Ago 2004 03:32, Tim Johnson escribió:
> Are you sure you want that top level to be an anonymous array instead of
> a hash?  This would make more sense (see below for how to access the
> values).  Note the {} brackets instead of the [] brackets.
>
> #
>
> my $a = {'cn'   => ['Barbara Jensen',
> 'Barbs Jensen'],
>  'sn'   =>  'Jensen',
>  'mail' =>  '[EMAIL PROTECTED]',
>  'objectclass' => ['top',
>'person',
>'organizationalPerson',
>'inetOrgPerson' ],
> };
>
> print $a->{objectclass}->[3]."\n"; #inetOrgPerson
> print $a->{sn}."\n"; #Jensen
>
> #
>
>
>
>
>
>
>
> -Original Message-
> From: Luis Daniel Lucio Quiroz [mailto:[EMAIL PROTECTED]
> Sent: Sunday, August 08, 2004 5:50 PM
> To: [EMAIL PROTECTED]
> Subject: COMPLEX ARRAY STRUCTURE
>
> Hi,
>
> $a = [
> 'cn'   => ['Barbara Jensen', 'Barbs Jensen'],
> 'sn'   => 'Jensen',
> 'mail' => '[EMAIL PROTECTED]',
> 'objectclass' => ['top', 'person',
> 'organizationalPerson',
>'inetOrgPerson' ],
>];
>
>
> I have this arrary structure, how should I read it?  For example how do
> I
> acces to "inetOrgPerson' value or Jesen value?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: COMPLEX ARRAY STRUCTURE

2004-08-09 Thread Ramprasad A Padmanabhan
This seems to be the result of a Net::LDAP search. I would suggest you
better read the perldoc for the module , there are methods to directly
give you the cn, sn etc from the entry. 

That way even if you upgrade the module and if the structure of the
object changes you wont have to change any of your code. Anyway If you
*really* want to use messy calls to the object directly you could do
this. 

To make it look less confusing you could just remove one level of a
reference like 

my %hash = @{$a};
now access the elements at will 

$sn = $hash{sn}# If you are sure there can only be one sn 

if(ref($hash{cn}) eq 'ARRAY') { 
   @listof_cn = @{$hash{cn}};
} else { 
  $cn = $hash{cn};
}


HTH
Ram

On Mon, 2004-08-09 at 06:19, Luis Daniel Lucio Quiroz wrote:
> Hi,
> 
> $a = [
> 'cn'   => ['Barbara Jensen', 'Barbs Jensen'],
> 'sn'   => 'Jensen',
> 'mail' => '[EMAIL PROTECTED]',
> 'objectclass' => ['top', 'person',
> 'organizationalPerson',
>'inetOrgPerson' ],
>];
> 
> 
> I have this arrary structure, how should I read it?  For example how do I 
> acces to "inetOrgPerson' value or Jesen value?
> 
> Thanks
> 
> LD



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: COMPLEX ARRAY STRUCTURE

2004-08-09 Thread Tim Johnson

Are you sure you want that top level to be an anonymous array instead of
a hash?  This would make more sense (see below for how to access the
values).  Note the {} brackets instead of the [] brackets.

#

my $a = {'cn'   => ['Barbara Jensen', 
'Barbs Jensen'],
   'sn'   =>  'Jensen',
 'mail' =>  '[EMAIL PROTECTED]',
 'objectclass' => ['top',
   'person',
   'organizationalPerson',
   'inetOrgPerson' ],
  };

print $a->{objectclass}->[3]."\n"; #inetOrgPerson
print $a->{sn}."\n"; #Jensen

#







-Original Message-
From: Luis Daniel Lucio Quiroz [mailto:[EMAIL PROTECTED] 
Sent: Sunday, August 08, 2004 5:50 PM
To: [EMAIL PROTECTED]
Subject: COMPLEX ARRAY STRUCTURE

Hi,

$a = [
'cn'   => ['Barbara Jensen', 'Barbs Jensen'],
'sn'   => 'Jensen',
'mail' => '[EMAIL PROTECTED]',
'objectclass' => ['top', 'person',
'organizationalPerson',
   'inetOrgPerson' ],
   ];


I have this arrary structure, how should I read it?  For example how do
I 
acces to "inetOrgPerson' value or Jesen value?


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]