Hacker News new | ask | show | jobs
by luckydude 1949 days ago
I wrote most of my first source management system (NSElite, mentioned elsewhere in this thread) in perl4. I was learning perl at the time and my first and second efforts were awful. Perl really lets you get sloppy and create unmaintainable code.

My 3rd rewrite was very stylized and, I felt, maintainable. Which proved to be true as I had to fix bugs in it.

I did weird stuff like using $whatever as the index into the @whatever array.

But I digress. On the <>, Little has argv so you can do

int main(string argv[]) { int i; string buf; FILE f;

    if (defined(argv[1]) && streq(argv[1], "-") && !defined(argv[2])) {
        while (buf = <STDIN>) bputs(buf);
    } else {
        for (i = 1; defined(argv[i]); i++) {
            if (defined(f = fopen(argv[i], "r")) {
                while (buf = <f>) puts(buf);
                fclose(f);
            } else {
                 fprintf(stderr, "unable to open '%s'\n", argv[i]);
            }
        }
    }
    return (0);
}

but why would you want to when all of that is

int main(string argv[]) { string buf;

    while (buf = <>) puts(buf);
    return (0);
}

I mean, come on, that's cat(1) in 8 lines of code.

edit: I need to learn hacker markup. My code looks like crap.

1 comments

It's indent by two spaces. Guessing your style:

  int main(string argv[]) { string buf;
    while (buf = <>) puts(buf);
    return (0);
  }