Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Substr Perl

by boftx (Deacon)
on Nov 26, 2013 at 11:41 UTC ( #1064395=note: print w/replies, xml ) Need Help??

in reply to Substr Perl

If I understand you correctly, you want to extract the "CN" term from the record string. Here is a somewhat brute-force approach but I think it demonstrates the principle you need to see.

# assuming you have a record string in $record and the field order is # always the same. my @fields = split(/\,/, $record); my $group = $fields[0]; # do this if you need to strip the "CN=" from the field $group =~ s/^CN=//; print $group . "\n";

Given this and your prior question about storing multiple values in a single DB column, I think you should read up on Perl regex, split and join as well as other basic text processing functions. Perl excels at this kind of work, but you need to know what tools you have available.

It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

Replies are listed 'Best First'.
Re^2: Substr Perl
by mba777 (Novice) on Nov 26, 2013 at 12:35 UTC
    sorry for my stupid questions but i'm actually no programmer ;), For example i have something like that:
    my @member = $entry->get_value ('memberOf'); my @memberof = grep(/\CN=ext\.Group\.([^,]+)/,@member); $member = join(',',@memberof); print "$uid -- $member\n";
    This code gives me the following output:
    Michael Douglas -- CN=ext.Group.eso,OU=External,OU=ExDistriGroups,OU=A +ccounts,DC=eso,DC=local,CN=ext.Group.test,OU=External,OU=ExDistriGrou +ps,OU=Accounts,DC=eso,DC=local,CN=ext.Group.test1,OU=External,OU=ExDi +striGroups,OU=Accounts,DC=eso,DC=local,CN=ext.Group.test2,OU=External +,OU=ExDistriGroups,OU=Accounts,DC=eso,DC=local
    What i want is:
    Michael Douglas -- eso, test, test1, test2
    Thanks Andy
      map instead of grep was the solution for me, thank you hdb !! Tanks to all ;)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1064395]
[Corion]: Meh, first round of escalations for me not wanting to fix in production what a project has mismanaged. Now another project, which eats up all the resources until end of this year wants to take that task and put it on my list of things as well.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2017-08-17 12:16 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (287 votes). Check out past polls.