|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
|
Thread Tools | Display Modes |
|
|
|||
Close. $attributes is a reference to an anonymous hash.
Quote:
|
|
|||
The '=>' separates the hash key from the hash value. It is a more visual appealing replacement then the ',' which also can be used for this purpose
Code:
%shell = ( Theo => '/bin/sh', Linus => '/bin/bash' ) ; print "\nTheo's shell : $shell{'Theo'} " ; print "\nLinus' shell : $shell{'Linus'} " ; $ perl hash-shell Theo's shell : /bin/sh Linus' shell : /bin/bash Code:
%os = ( 'Theo', 'OpenBSD', 'Linus', 'Linux' ); print "\nTheo's OS : $os{'Theo'} " ; print "\nLinus' OS : $os{'Linus'} " ; $perl hash-os Theo's OS : OpenBSD Linus' OS : Linux
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
||||
Thanks for the replies. As I wrote a few scripts, I am getting familiar with the "hash" concept and Perl. But this is where it becomes confusing:
For the same hash I pasted in my first post, whenI print $attributes I get: Code:
ARRAY(0x811a214)
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." |
|
||||
No.
hashes can not have duplicate keys. also, the keys in a hash are not ordered. For example, Code:
%hash1 = @array1; @array2 = %hash1 ; %hash2 = @array2; arrays have a small performance advantage. and neither is particularly space efficient in perl. Last edited by ephemera; 18th November 2008 at 07:13 PM. |
|
||||
Quote:
the => operator is effectively a comma operator where the left hand object is taken as a double quoted string. in the given code its probably used to make the association clear (like J65nko said). i am not sure why they haven't used a hash reference. possibly for a small performance gain? Last edited by ephemera; 18th November 2008 at 07:12 PM. |
|
||||
Quote:
Code:
$ldapHandle->add($dn, attr => $attributes); Code:
$result = $ldap->add("uid=john,ou=People,dc=leapster,dc=org", attr => [ 'cn' => 'John Smith', 'sn' => 'Smith', 'uid' => 'john', 'givenName' => 'John', 'homePhone' => '555-2020', 'mail' => 'john@domain.name', 'objectclass' => [ 'person', 'inetOrgPerson'] ] );
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." |
|
||||
Furhter testing indicates that :
Code:
foreach my $i (@$attributes) { print $i . ENDL; } Code:
foreach my $i (%$attributes) { print $i . ENDL; } Now, how am I expected to provide a key-value pair when I need to work with an array?
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." |
|
||||
Quote:
though, assigning an array to a hash and vice-versa is valid (with a caveat) , please see the example i gave earlier (#6). Last edited by ephemera; 18th November 2008 at 07:34 PM. |
|
||||
Quote:
The format is given in the POD: http://search.cpan.org/~gbarr/perl-l...b/Net/LDAP.pod Last edited by ephemera; 18th November 2008 at 07:40 PM. |
|
||||
Thanks for the explanations ephemera. Understood and script fixed.
Thanks!
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." |
|
|||
Most of these things you can find in the man page perldsc (perl data sctructures cookbook) and perlreftut
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
||||
Thanks J65nko, I'll take good notes.
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Basic networking fail. | diw | OpenBSD General | 13 | 31st March 2009 09:29 AM |
Basic sshd hardening | anomie | Guides | 12 | 12th September 2008 03:39 AM |
C 2D arrays | jgroch | Programming | 16 | 2nd August 2008 01:54 AM |
need some basic help on ifconfig | daemon-dd | FreeBSD General | 4 | 29th July 2008 03:21 PM |
ksh arrays | mtx | Programming | 11 | 7th May 2008 10:00 AM |