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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |