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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.