I'm not sure from your question what exactly you're trying to accomplish. Here are a couple of options...

  1. Determine if the value in $CD is valid
    my $valid_chars = 'CETLMNPA'; if ($CD =~ m/^[$valid_chars](?:,[$valid_chars])*$/) { print "Valid!" } else { die "Invalid!" }

    Let's break down that regular expression:

    m/ ^[$valid_chars] #the string must start with one of the valid char +s (?: #start group, but don't capture! , #could have a comma [$valid_chars] #and another valid char )* #and that comma+valid char could repeat 0 or more + times $ #until the end of the string /x #this is here to allow me to use all these commen +ts
  2. Use as configuration values

    For example, if I want to know at various points in code if a given flag is set:

    my %config = map { $_ => 1 } split(',', $CD); ## later on... if ( $config{L} ) { print "L was set!" }

    You might use the validation from above in combination with this.

<radiant.matrix>
Ramblings and references
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

In reply to Re: Regular expression for combination of data by radiantmatrix
in thread Regular expression for combination of data by isha

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.