trochee: (amused)
[personal profile] trochee

non-geeks, avert thine eyes.

I just had to rant somewhere about a very bad paragraph of perl:

opendir (DIR, $dir) || die "cannot open $dir\n";
while ($_ = readdir(DIR))
{
    if(/^foo/){;}       #OK
    else{next;}

   if(/^bar/){next;}   # skip bar data
   print STDERR "$_ ";
   `csh -c "cat $dir/$_/* | $pipethrough >> $dir/temporary"`;
}
`csh -c "cat  $dir/temporary | anonymize > $output"`;
print STDERR "\nDone\n";
closedir(DIR);
`rm $dir/temporary`;
exit;
# more code here...

Augh. I'll rewrite this when I have time.

Bonus question: How many processes are started by the following?

`csh -c "cat  $dir/temporary | anonymize > $output"`;

Here's my rewrite:
opendir (DIR, $dir) or die "cannot open $dir: $!\n";
while ($_ = readdir <DIR>)
{
   next unless /^foo/; # must begin with foo
   next if /^bar/;     # skip beginning with bar

   warn "$_\n";
   `cat $dir/$_/* | $pipethrough >> $dir/temporary`;
}
`anonymize < $dir/temporary > $output`;
warn "\nDone\n";

closedir(DIR) or die "couldn't close directory $dir: $!\n";
unlink($dir/temporary) or warn "couldn't unlink $dir/temporary: $!\n";

Re: augh!

Date: 2003-10-24 06:05 am (UTC)
From: [identity profile] trochee.livejournal.com
csh is so broken that it wouldn't surprise me if it needed 21 pids just to patch bugs:

http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

Re: augh!

Date: 2003-10-24 06:54 am (UTC)
ext_183001: openvein spiral, white on black. (Default)
From: [identity profile] lx.livejournal.com
Haha, thanks for the link. I've never actually even seen csh in active use (though I have seen the ostensibly fixed tcsh on MacOS X as the default shell), now I'll know to avoid it with good reason. ;)

Of course, if the 21 pid thing is really csh, that amounts to something like 25 additional procs to this script for each invocation of that system call! :) Woooo.

Profile

trochee: (Default)
trochee

June 2016

S M T W T F S
   1234
567 89 1011
12131415 161718
19202122232425
2627282930  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 31st, 2025 04:03 am
Powered by Dreamwidth Studios