in reply to Re: Parsing of LDAP entry (get_value( $var, asref => 1 );
in thread Parsing of LDAP entry

Thank you for reply.

Please take a look for my example:

(...) my $ref = $entry->get_value ( 'changes', asref => 1 ); print Dumper($ref);

Execution:

perl test.pl $VAR1 = [ 'delete: employeeType employeeType: Intern - add: employeeType employeeType: No Longer Employed - add: description description: On 30-07-2013 05:17 removed from source. - add: nsAccountLock nsAccountLock: true - replace: modifiersname modifiersname: cn=mmariusz,ou=people,ou=testENV - replace: modifytimestamp modifytimestamp: 20130730031746Z - '

So, this is stil "multiline" result in one variable. Probably I need to create some kind of function/object and make a parser for that:

function magic() { my $string = shift; # some magic should be placed here :) #sample return return @replaced_attrs,@added_attrs,@delete_attrs; }

Replies are listed 'Best First'.
Re^3: Parsing of LDAP entry (get_value( $var, asref => 1 );
by Anonymous Monk on Jul 31, 2013 at 07:38 UTC

      Uff solved:

      (...) my $chang = &_changes($entry->get_value("changes")); my %changes = %$chang; sub _changes { my $changesSTR = shift; my (%changes, @tmp); $changesSTR =~ s/\n/ /g; foreach my $element(split(/\s-\s/,$changesSTR)){ if ($element =~ m/(replace|add|delete):\s+([^\s]*)\s*\w+\s +*:\s*(.*)$/) { my ($var1,$var2,$var3) = ($1, $2 ,$3); push @tmp,$var3 ; $changes{$var1}{$var2} .= "@tmp" ; @tmp=undef; } elsif ($element =~ m/(replace|add|delete):\s+([^\s]*)$/ +){ $changes{$1}{$2} .= "undef" ; } } return \%changes; }

      Maybe solution is not pretty, but works ;)