Re: more than one set of records separated by blank lines
- From: Jim Gibson <jgibson@xxxxxxxxxxxxxxxxx>
- Date: Tue, 19 Jul 2005 10:38:12 -0700
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 =---
.
- References:
- more than one set of records separated by blank lines
- From: marcorice
- more than one set of records separated by blank lines
- Prev by Date: Perl Developer Opportunity at Top-Tier Investment Bank - Chicago
- Next by Date: Re: copy contructor
- Previous by thread: more than one set of records separated by blank lines
- Next by thread: Re: more than one set of records separated by blank lines
- Index(es):
Relevant Pages
|