in reply to Re: A conversation with a C programmer
in thread A conversation with a C programmer

Along those lines, it probably would have been a nice gesture to let the C programmer know that
next if($file eq "."); next if($file eq "..");
can be condensed to
next if $file =~ /^\.{1,2}$/;
Isn't that more Perlish, and help the programmer see more of the usefulness of regexes without making him too lost in what is going on? But now that I think about it, the whole snippet can just be compressed to something like
opendir(TARGET, $target); while($file = readdir(TARGET)) { &process_new_file($file) if $file =~ /\.xls$/; }
right? Do you think that would rock the boat too much?

Replies are listed 'Best First'.
Re^3: A conversation with a C programmer
by Anonymous Monk on Mar 15, 2006 at 20:38 UTC
    opendir my $dh, $target; /\.xls$/ and process_new_file($_) while readdir $dh;

    I started out writing this facetiously, but now I kind of like it! It reads very nicely. YMMV =)

Re^3: A conversation with a C programmer
by dynamo (Chaplain) on Mar 16, 2006 at 00:13 UTC
    I think
    next if $file =~ /^\.\.?$/;
    or even
    next if $file =~ /^\.+$/; # no longer recommended. see below
    is much nicer than
    next if $file =~ /^\.{1,2}$/;

    But that's just me.

    UPDATE/note: yes, the second one will also match files named with any quantity of dots as long as that's the entire filename. In practice, I've never seen a file that started with "..", but I agree it's an issue.

      yes, the second one will also match files named with any quantity of dots as long as that's the entire filename. In practice, I've never seen a file that started with "..", but I agree it's an issue.

      I have, but only on a machine that's been broken into. It is, or at least used to be, common to hide malicious software inside directories called ... -- of course, these days all the l33t kiddies are using loadable kernel modules to hide their directory trees anyway, so it may not be as relevant.

      --
      @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

      But that's just me.

      *nod*, I don't at all like your second preference.