From: Werner R. <we...@pu...> - 2000-10-13 20:21:07
|
I want to do something like $res = $ldap->add ( dn => "dc=${dc},$base", attrs => [%myhash] ); Unfortunately only one key/value pair of %myhash is used for the entry. I want to use a hash since I have to create entries with a varying set of attributes and I don't know how I could do this in a simple way. Werner |
From: Mark W. <mew...@un...> - 2000-10-13 21:12:55
|
The value of the hash would have to contain an array. like this: my $array = ['value','value','value']; or $array->[0] = 'value'; $array->[1] = 'value'; $hash->{$key} = $array; or it might have to be $hash->{$key} = @$array; Mark On Fri, 13 Oct 2000, Werner Reisberger wrote: > I want to do something like > > $res = $ldap->add ( > dn => "dc=${dc},$base", > attrs => [%myhash] ); > > Unfortunately only one key/value pair of %myhash is used for the > entry. I want to use a hash since I have to create entries with a varying > set of attributes and I don't know how I could do this in a simple way. > > Werner > |
From: Graham B. <gb...@po...> - 2000-10-13 22:00:58
|
On Fri, Oct 13, 2000 at 04:03:25PM -0500, Mark Wilcox wrote: > The value of the hash would have to contain an array. > > like this: > my $array = ['value','value','value']; > or > $array->[0] = 'value'; > $array->[1] = 'value'; > > > $hash->{$key} = $array; Yes that is right. > or it might have to be > $hash->{$key} = @$array; Um, no. That would assign the number 3 to $hash->{$key} Graham. > > Mark > > On Fri, 13 Oct 2000, Werner Reisberger wrote: > > > I want to do something like > > > > $res = $ldap->add ( > > dn => "dc=${dc},$base", > > attrs => [%myhash] ); > > > > Unfortunately only one key/value pair of %myhash is used for the > > entry. I want to use a hash since I have to create entries with a varying > > set of attributes and I don't know how I could do this in a simple way. > > > > Werner > > > |
From: Werner R. <we...@pu...> - 2000-10-15 10:48:21
|
On Fri, Oct 13, 2000 at 04:03:25PM -0500, Mark Wilcox wrote: > The value of the hash would have to contain an array. > > like this: > my $array = ['value','value','value']; > or > $array->[0] = 'value'; > $array->[1] = 'value'; OK, this way I could create several attribute/value pairs where the attribute (key) doesn't change but I want to have several different attributes in my hash. Example: dc => 'mydom.com', sn => 'Brown', cn => 'C B' I want to put these attribute/value pairs into a structure (hash ...) and supply this structure to the attrs method to avoid writing each attribute/value pair seperately: $ldap->add ( dn => $dn, attrs => [%myhash] ); I used an array of anonymous hashes and an array and a hash within the anonymous array. First case doesn't work at all, in the last two trials only one attribute is added to the entry. Werner |
From: Chris R. <chr...@me...> - 2000-10-16 09:19:50
|
Werner Reisberger <we...@pu...> wrote: > On Fri, Oct 13, 2000 at 04:03:25PM -0500, Mark Wilcox wrote: >> The value of the hash would have to contain an array. >> >> like this: >> my $array = ['value','value','value']; >> or >> $array->[0] = 'value'; >> $array->[1] = 'value'; > > OK, this way I could create several attribute/value pairs where the > attribute (key) doesn't change but I want to have several different > attributes in my hash. Example: > > dc => 'mydom.com', > sn => 'Brown', > cn => 'C B' > > I want to put these attribute/value pairs into a structure (hash ...) and > supply this structure to the attrs method to avoid writing each > attribute/value pair seperately: > > $ldap->add ( > dn => $dn, > attrs => [%myhash] ); > > I used an array of anonymous hashes and an array and a hash within the > anonymous array. First case doesn't work at all, in the last two trials > only one attribute is added to the entry. > > Werner Couldn't you just use: $ldap->add ( dn => $dn, attrs => [ keys %myhash ] ); Cheers, Chris |
From: Graham B. <gb...@po...> - 2000-10-16 10:00:25
|
On Mon, Oct 16, 2000 at 10:19:21AM +0100, Chris Ridd wrote: > Werner Reisberger <we...@pu...> wrote: > > On Fri, Oct 13, 2000 at 04:03:25PM -0500, Mark Wilcox wrote: > >> The value of the hash would have to contain an array. > >> > >> like this: > >> my $array = ['value','value','value']; > >> or > >> $array->[0] = 'value'; > >> $array->[1] = 'value'; > > > > OK, this way I could create several attribute/value pairs where the > > attribute (key) doesn't change but I want to have several different > > attributes in my hash. Example: > > > > dc => 'mydom.com', > > sn => 'Brown', > > cn => 'C B' > > > > I want to put these attribute/value pairs into a structure (hash ...) and > > supply this structure to the attrs method to avoid writing each > > attribute/value pair seperately: > > > > $ldap->add ( > > dn => $dn, > > attrs => [%myhash] ); > > > > I used an array of anonymous hashes and an array and a hash within the > > anonymous array. First case doesn't work at all, in the last two trials > > only one attribute is added to the entry. > > > > Werner > > Couldn't you just use: > > $ldap->add ( dn => $dn, > attrs => [ keys %myhash ] ); No, thats not right. Look at the example in the docs $mesg = $ldap->add( $DN, attrs => [ name => 'Graham Barr', attr => 'value1', attr => 'value2', multi => [qw(value1 value2)] ] ); This adds 4 attributes, each with a single value except 'multi' which has multiple values. So if %myhash has an entry per attribute. The values need to be either the value (for single valued attributes) or a reference to an array of values (for multi or singled-valued attributes) Graham. |
From: Chris R. <chr...@me...> - 2000-10-16 10:40:19
|
Graham Barr <gb...@po...> wrote: > On Mon, Oct 16, 2000 at 10:19:21AM +0100, Chris Ridd wrote: >> Werner Reisberger <we...@pu...> wrote: >> > On Fri, Oct 13, 2000 at 04:03:25PM -0500, Mark Wilcox wrote: >> >> The value of the hash would have to contain an array. >> >> >> >> like this: >> >> my $array = ['value','value','value']; >> >> or >> >> $array->[0] = 'value'; >> >> $array->[1] = 'value'; >> > >> > OK, this way I could create several attribute/value pairs where the >> > attribute (key) doesn't change but I want to have several different >> > attributes in my hash. Example: >> > >> > dc => 'mydom.com', >> > sn => 'Brown', >> > cn => 'C B' >> > >> > I want to put these attribute/value pairs into a structure (hash ...) >> > and supply this structure to the attrs method to avoid writing each >> > attribute/value pair seperately: >> > >> > $ldap->add ( >> > dn => $dn, >> > attrs => [%myhash] ); >> > >> > I used an array of anonymous hashes and an array and a hash within the >> > anonymous array. First case doesn't work at all, in the last two trials >> > only one attribute is added to the entry. >> > >> > Werner >> >> Couldn't you just use: >> >> $ldap->add ( dn => $dn, >> attrs => [ keys %myhash ] ); > > No, thats not right. Look at the example in the docs > > $mesg = $ldap->add( $DN, > attrs => [ > name => 'Graham Barr', > attr => 'value1', > attr => 'value2', > multi => [qw(value1 value2)] > ] > ); > > This adds 4 attributes, each with a single value except 'multi' which has > multiple values. > > So if %myhash has an entry per attribute. The values need to > be either the value (for single valued attributes) or a reference > to an array of values (for multi or singled-valued attributes) > > Graham. Yup, you're right. Consider this a "Doh!" Cheers, Chris |