> On 6 Oct 2014, at 18:57, punit jain <[email protected]> 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/>,[email protected] <mailto:[email protected]>,[email protected] 
> <mailto:[email protected]>,[email protected] 
> <mailto:[email protected]>,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/>
> [email protected] <mailto:[email protected]>
> [email protected] <mailto:[email protected]>
> [email protected] <mailto:[email protected]>
> 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,[email protected],[email protected],[email protected],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