Dear Almighty Perl Mongers,

My thought was to convert this mess to a regex substitution.

$bday = "8/16/97"; $firstname = "Benjamin"; $lastname = "Biederman"; @DOB = split /\//, $bday; @month = split //, $DOB[0]; @day = split //, $DOB[1]; $digits_month = @month; $digits_day = @day; $temp_month = $DOB[0]; $temp_day = $DOB[1]; if ($digits_month==1) { $bday = "0"; $bday .= $temp_month; } else { $bday = $temp_month; } if ($digits_day==1) { $bday .= "0"; $bday .= $temp_day; } else { $bday .= $temp_day; } @new_username_a = split //, $firstname; @new_username_b = split //, $lastname; $login_name = lc $new_username_a[0]; $login_name .= lc $new_username_b[0]; $login_name .= $bday;
to something like ---
$login_name = "$firstname $lastname $bday"; $login_name = s/^(^\C)\s(^\C)\s(^\d{1,2})\/(\d{1,2})\/(\d{1,2})/$1$2$3 +$4/; #notice that to 2 digit bit is not reflected by this regex
Thanks,
Chris

janitored by ybiC: Balanced <code> tags around code only, retitle from " REGEX optimization" for better searching


In reply to Convert split to regex by 3dbc

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.