Update:It seems I've misread your request, you do not want to replace anything. Ignore the answer below.
"Is it possible to get only the term "eso" and "test" out of these strings? What i want to say i need this term: CN=ext.Group."MY TERM",OU=External,OU=ExDistriGroups,OU=Accounts,DC=eso,DC=local"Your specification isn't quite right, if you replace "eso" with "my term" you'll break the DC part of your LDAP connection string.
Specify a groupname, identify the strings you wish to replace e.g. "Group.eso", rather than all the "eso"s, use a regex to replace them:
#!/usr/bin/perl use strict; use warnings; my $groupname = "derp"; my %replaceGroups = ( "Group.test" => "Group.$groupname", "Group.eso" => "Group.$groupname", ); my $regex = join "|", keys %replaceGroups; $regex = qr/$regex/; # both cnstrings for testing. my $cnstring = "CN=ext.Group.eso,OU=External,OU=ExDistriGroups,OU=Acco +unts,DC=eso,DC=local"; #my $cnstring = "CN=ext.Group.test,OU=External,OU=ExDistriGroups,OU=Ac +counts,DC=eso,DC=local"; $cnstring =~ s/($regex)/$replaceGroups{$1}/g; print "$cnstring\n";
Output:
CN=ext.Group.derp,OU=External,OU=ExDistriGroups,OU=Accounts,DC=eso,DC= +local
Update: fixed spelling mistake.
In reply to Re: Substr Perl
by marto
in thread Substr Perl
by mba777
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |