Looking for a somewhat clever way to do this.

I have an input file which consists of fixed length (10 characters) lines containing a-z.

For each line, I want to build and print a regexp string that I will use elsewhere.

The regexp string will begin (before processing each line):

'/bin/grep .......... /path/to/some/file'

For each 'x' character in the input file, I want to replace the corresponding dot in the regexp with say the corresponding digit of pi (1415926535).

For example, if a line in input file contains an 'x' in the third character (but not the first and second), the regexp string should become:

'/bin/grep ..1....... /path/to/some/file'

If the next 'x' occurs in the seventh character of the line, then the string should become:

'/bin/grep ..1...6... /path/to/some/file'

I feel like some simple way should exist to do this, but my attempts have just become a mess of code.


In reply to string substitution by Anonymous Monk

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.