This is great. I especially like the distinction between [01:20] and [1:20].

The zsh shell has a brace expansion function, so you can write this in zsh:

echo f-{fred,barney,vilma}/h{08..22}.t
which prints
f-fred/h08.t f-fred/h09.t f-fred/h10.t f-fred/h11.t f-fred/h12.t f-fre +d/h13.t f-fred/h14.t f-fred/h15.t f-fred/h16.t f-fred/h17.t f-fred/h1 +8.t f-fred/h19.t f-fred/h20.t f-fred/h21.t f-fred/h22.t f-barney/h08. +t f-barney/h09.t f-barney/h10.t f-barney/h11.t f-barney/h12.t f-barne +y/h13.t f-barney/h14.t f-barney/h15.t f-barney/h16.t f-barney/h17.t f +-barney/h18.t f-barney/h19.t f-barney/h20.t f-barney/h21.t f-barney/h +22.t f-vilma/h08.t f-vilma/h09.t f-vilma/h10.t f-vilma/h11.t f-vilma/ +h12.t f-vilma/h13.t f-vilma/h14.t f-vilma/h15.t f-vilma/h16.t f-vilma +/h17.t f-vilma/h18.t f-vilma/h19.t f-vilma/h20.t f-vilma/h21.t f-vilm +a/h22.t
Zsh makes the distinction between {08..22} and {8..22}. Bash 3.0 has cloned this numeric brace expansion feature too (it had non-numeric brace expansion originally), but it expands {08..11} as 8 9 10 11. (Brace expansion with multiple braces sometimes expand in a different order in the shells and your program.)

By the way, your program does not fully expand m[2:5]-{a:t:g:c}, it just prints the four strings m[2:5]-a m[2:5]-t m[2:5]-g m[2:5]-c. Is that intentional?

Also, your program does not seem to be able to expand braces embedded in each other, such as {/usr{:/local}:/var}/lib. Bash expands this to /usr/lib /usr/local/lib /var/lib.


In reply to Re: String expansion script by ambrus
in thread String expansion script by blazar

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.