A little exercise using a sequence of bash shell commands (I'm including the "$" shell prompt, to make it clear which lines are actual commands; the lines without "$" are either keyboard input or command output):
$ cat <<EOF > test.in one o n e two t w o three t h r e e EOF $ perl -pe 's/(\w+)/\U$1/' < test.in > test.out $ cat test.out ONE o n e TWO t w o THREE t h r e e
If you want to store the one-line perl script as an executable file (so that you don't have to type  perl -pe 's/(\w+)/\U$1/' every time you want to up-case the first word of every line in a data stream), you would do this:
$ cat <<EOF > upcase-firstword #!/usr/bin/perl -p s/(\w+)/\U$1/; EOF $ chmod +x upcase-firstword $ upcase-firstword < test.in > test2.out $ diff test.out test2.out
Move the "upcase-firstword" file to some directory in your PATH, and you can run it no matter which directory you are in at the moment. (You can give it a shorter name if you like.)

Using the "cat" command to write a perl script like that can be lots of fun, although many programmers would not consider it to be their preferred method for programming.


In reply to Re^3: Changing the first word to uppercase by graff
in thread Changing the first word to uppercase 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.