> On 6 Oct 2014, at 18:57, punit jain <contactpunitj...@gmail.com> wrote:
> 
> Thanks Paul. However I think I couldnot explain the problem.
> 
> The issue is when I have mailid's as well as a part of input stream.
> 
>  Input stream ---> $str="ldap:///uid=user1,ou=People,o=test.com 
> <http://test.com/>,a...@test.com <mailto:a...@test.com>,t...@test.com 
> <mailto:t...@test.com>,r...@test.com 
> <mailto:r...@test.com>,ldap:///uid=user2,ou=People,o=test.com 
> <http://test.com/>,ldap:///uid=user3,ou=People,o=test.com <http://test.com/>"

Suddenly you've switched to double quotes.  That won't do unless you escape the 
@s.

> expected output
> ============
> first=uid=user1,ou=People,o=test.com <http://test.com/>
> first=a...@test.com <mailto:a...@test.com>
> first=t...@test.com <mailto:t...@test.com>
> first=r...@test.com <mailto:r...@test.com>
> first = uid=user2,ou=People,o=test.com <http://test.com/>
> first = uid=user3,ou=People,o=test.com <http://test.com/>

Try this.

#!/usr/bin/perl
use strict;
my $str 
='ldap:///uid=user1,ou=People,o=test.com,a...@test.com,t...@test.com,r...@test.com,ldap:///uid=user2,ou=People,o=test.com,ldap:///uid=user3,ou=People,o=test.com';
my @ldap = split 'ldap:///', $str;
my $concat;
for (@ldap){
  for (split /,/) {
    if (/\@/) {
      $concat .= "\nfirst=$_"
    } elsif (/uid/) {
      $concat .= "\nfirst=$_,"
    } else {
      $concat .= "$_,"
    }
  }
}
my @printlist = split /\n/, $concat;
for (@printlist) {
  unless (/^$/){ # skip empty lines
    s~,$~~g; # remove trailing commas
    print "$_\n";
  }
}


#JD



Reply via email to