Re: more than one set of records separated by blank lines



In article <1121791258.025996.117480@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
<marcorice@xxxxxxxxx> wrote:

> I am new to perl and have had this problem for a while now.
> I'm doing an ldapsearch with the following result of a record set.
>
> CN=junk
> mail=emailaddess
> employeeID=somenumber
> givenName=first_name
> middleName=middle_name
> sAMAccountName=somnumber_or_string
> sn=last_name
> telephoneNumber=telephone_number
> userPrincipalName=some_email_string
> extensionAttribute13=somenumber
>
> Sometimes I get more than one set of records separated by blank lines.
> I need to do somekind of loop that evaluates each set separately.
>
> chomp(@info= (`ldapsearch -p $PORT -b DC=com -s sub -h $SHOST
> "(&(sn=$lname)(givenName=$fname))" givenName middleName sAMAccountName
> sn
> employeeID mail telephoneNumber extensionAttribute13
> userPrincipalName`));
> foreach $list (@info) {
> if ($list =~ s/extensionAttribute13=//){
> $ntuid = $list;
> }
> elsif ($list =~ s/telephoneNumber=//){
> $telenum = $list;
> ........

So what part of this process are you having trouble with? You seem well
on the way to solving your problem.

One suggestion: use a hash to store your data and use split to extract
the keys and values:

my %data;
foreach $list ( @info ) {
my( $key, $val ) = split(/=/,$list);
$data{$key} = $val;
}

$ntuid = $data{extensionAttribute13};
etc.

You can use the presence of a blank line in your input to signify
completion of an entry:

foreach $list ( @info ) {
if( $list =~ /^\s*$/ ) {
# entry complete -- process and clear %data
}else{
etc.

If your data is always in the same format, you can count data lines or
trigger on the last entry instead.

Please try posting a complete program if you are having more trouble.
Since we do not all have access to an ldap server, check out the use of
the special <DATA> file handle to include test data in a test program.

Thanks.


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
.



Relevant Pages

  • f0dders fabulous folly.
    ... its target audience that the mistakes being sold by f0dder are not ... Following is the test program that proves this very clearly. ... proof that prototype duplication of an API ... IAT Entry ...
    (alt.lang.asm)
  • Re: Once Again For Your Posting Pleasure - John C. Dvorak Comments On MacOS X
    ... Microsoft is "in trouble" because the barrier to entry into Vista is ...
    (comp.sys.mac.advocacy)
  • Re: I want a field to check itself for duplicates
    ... Now having trouble with the Bookmark line. ... Bookmark stLinkCriteria is valid for each different entry. ... > I too still have a lot to learn and would not have been able to answer Erics ...
    (microsoft.public.access.formscoding)
  • Re: Newbie: Help writing a sproc
    ... using the test data you posted earlie (changing the time on one row ... If you're sure you didn't make a mistake in copying the query, ... query will set the userid to NULL if the userid has at least one entry in ... So if userid 3 has an entry of 70 ...
    (microsoft.public.sqlserver.programming)
  • [OT]: some "newbie" questions
    ... > I am having some trouble with the earlier excercises and some ... create a text file and put test data in it. ... it also has the benefit of letting the system take care of EOF ...
    (comp.lang.c)