I cast my incantation in C, diving headlong into the danger:
void version(char *progname, char *rcs_rev) { int major = -1; int minor = -1; char *where = NULL; char buf[5]; char nulls[5] = {'\000', '\000', '\000', '\000', '\000'}; int bufptr = 0; if(strchr(rcs_rev, ':') == NULL) { printf("%s, no RCS revision given.\n", progname); return; } where = strchr(rcs_rev, ' '); where++; while(where[0] != ' ') { if(where[0] != ' ' && where[0] != '.') { buf[bufptr++] = where[0]; } else if(where[0] == '.') { if(major == -1) { major = atoi(buf); } else if(minor == -1) { minor = atoi(buf); break; } bufptr = 0; memcpy(buf,nulls,5); } else break; where++; } fprintf(stderr,"%s version %d.%d\n",progname,major,minor); }

Then I realized I had spent an hour writing a simple getopt thing for my small tool (clone of 'from'), and most of time had been sunk on that part that merely prints the version number from RCS.

Then, in 2 minutes, I wrote the same in Perl:

sub version { my ($progname, $rcs_rev) = (@_); if($rcs_rev !~ /:/) { print "$progname, no RCS version given.\n"; return; } $rcs_rev =~ /Revision: (\d+)\.(\d+)/; my ($major, $minor) = ($1, $2); print "$progname version $major.$minor\n"; }

I hope people will learn to understand why I think Perl is such a nice language.


In reply to What I Did Today To Prove Perl Beats C 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.