chiark / gitweb /
Code cleanups:
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 4 Sep 2013 20:36:34 +0000 (21:36 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 4 Sep 2013 20:36:34 +0000 (21:36 +0100)
* random-word: use strict; -w.

debian/changelog
scripts/random-word

index 6bd8b40e4465f598e141ce9c3e26df53e198898b..0fa99b32e20fc0a1dcdf67bd477ff826732e57a3 100644 (file)
@@ -1,6 +1,8 @@
 chiark-utils (4.2.1~~iwj1) unstable; urgency=low
 
+  Code cleanups:
   * random-word: Some perl-mode emacs formatting glitch workarounds.
+  * random-word: use strict; -w.
 
  --
 
index ddd6c5205158684538fdac95268496eaed13821a..427e4d08795710586fb6f02229f78cadb98b0ac4 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/perl -w
 
 # Copyright 2004 Ian Jackson <ian@chiark.greenend.org.uk>
 #
 # with this program; if not, consult the Free Software Foundation's
 # website at www.fsf.org, or the GNU Project website at www.gnu.org.
 
+use strict;
+
 use IO::Handle;
 use IO::File;
 use POSIX;
 
-$want= 1;
-$filename= "/usr/share/dict/words";
-@randfile= ("/dev/urandom", "/dev/random");
+our $want= 1;
+our $filename= "/usr/share/dict/words";
+our @randfile= ("/dev/urandom", "/dev/random");
 
 sub fail ($) { die "random-word: $_[0]\n"; }
 open D, ">/dev/null" or fail("open /dev/null: $!");
 
-while ($ARGV[0] =~ m/^\-/) {
+while (@ARGV && $ARGV[0] =~ m/^\-/) {
     $_= shift @ARGV;
     if (m/^\-\-?$/) {
        last;
@@ -49,6 +51,9 @@ sub debug ($) {
        or fail("write debug: $!");
 }
 
+our $randfile;
+our $r;
+
 for $randfile (@randfile) {
     $r= new IO::File "$randfile", 'r';
     debug("open $randfile ".($r ? "ok" : "failed $!"));
@@ -58,17 +63,19 @@ for $randfile (@randfile) {
 $r or fail("could not open any random device: $!\n (tried @randfile)");
 $r->autoflush(0);
 
-$w= new IO::File $filename, 'r';
+our $w= new IO::File $filename, 'r';
 $w or fail("cannot open $filename: $!");
 debug("open $filename ok");
-@words= <$w>;
+our @words= <$w>;
 $w->error and fail("cannot read $filename: $!");
 debug("read $filename ok");
 
+our @out;
 while (@out < $want) {
+    my $rbytes;
     $!=0; read $r,$rbytes,4;
     length $rbytes==4 or fail("cannot read $randfile: $!");
-    $wordno= unpack 'L',$rbytes;
+    my $wordno= unpack 'L',$rbytes;
     $wordno &= ~0x80000000;
     $wordno %= @words;
     $_= $words[$wordno];