Hi everyone, I am in need of assistance D: I am writing a battleship program, and I take in user coordinates with the format of a10, b1 , c5 etc. The module I have takes in the coordinates with the format of A:10, B:1, C:5 etc. I wrote some very poor code which has uninitialized errors, but it gets the job done. This is it here:
$combined = uc($topLeftCoord); @chars = (split //, $combined); print "@chars\n"; if ($chars[2] == 0){ $combined = $chars[0] . ":" . $chars[1] . $chars[2]; } else{ $combined = $chars[0] . ":" . $chars[1]; }
This is just a bit of it, but it's where the problem lies. I uppercase the letter, split on every new character, print for debugging, my board is 10x10, so the max it can be is 10, so if the 3rd element is 0, I'll concatenate it onto the string for use in my module. It's very poorly written but that's why I'm here, to make it better =P. How would I use substitution with regular expressions to do this job? Or would it be better to split and concatenate. Thanks for any help!

In reply to How would I change a10 into A:10 in perl? by Tails

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.