dMv (daemonv) wrote,

Learning Moment

My brain is not quite spun up yet.

# Learning Point:
# When writing a loop that goes through the contents of
# a directory, that causes a new file to be created *in
# that directory*, bad things can happen if the new file
# matches the criteria of the file name filter *and* the
# directory listing is dynamic.

(run as something.c because you forgot that you don't have to give it the source file(s) on the command line anymore. Not great code sample below. And yes, I fixed the problem in one of the dozen or so ways I can imagine doing so.)

$postfix = ( $#ARGV > -1 ) ? shift @ARGV : ".unc";

sub annotate( $file );

opendir( HERE, "." ) || die "can't open dir .\n";

while ( $f = readdir HERE )
&annotate($f) if ($f =~ /\.c$/);

sub annotate( $file )
my $file = shift @_;
print "Annotating $file.\n";
open( SRC, "<$file" ) || die "can't read file $file\n";;
open( ANN, ">$file$postfix" ) || die "can't open file $file$postfix\n";

  • Three Videos

    After spending the day away from the social networks, and then cramming to catch up, the links in aggregate start to tell stories together. Here are…

  • (no subject)

    13:34 Boxed water is better? #

  • (no subject)

    13:12 @ cameo do you mean something like ? #

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded