[2654] in BarnOwl Developers
Re: [PATCH] add a random zsig function
daemon@ATHENA.MIT.EDU (Anders Kaseorg)
Sun Sep 19 03:43:58 2010
Date: Sun, 19 Sep 2010 03:43:56 -0400 (EDT)
From: Anders Kaseorg <andersk@MIT.EDU>
To: Kevin Riggle <kevinr@free-dissociation.com>
cc: barnowl-dev@mit.edu
In-Reply-To: <1284880026-392-1-git-send-email-kevinr@free-dissociation.com>
On Sun, 19 Sep 2010, Kevin Riggle wrote:
> +sub random_zephyr_signature=20
> +{=20
> + my $zsigfile =3D "$ENV{'HOME'}/.zsigs";=20
> + open FILE, $zsigfile or die "No zsigfile $zsigfile";=20
> + while (<FILE>) {=20
> + push @lines, $_ unless /^#/ || /^\s*$/;=20
> + }=20
> + close FILE;=20
> + my $zsig =3D $lines[int(rand(scalar @lines))];=20
> + chomp $zsig;=20
> + return $zsig;=20
> +}
@lines and FILE are global variables. The open call lacks a mode ('<'),=20
and its failure does not necessarily imply that the zsig file doesn=E2=80=
=99t=20
exist. Also, if ~/.zsigs is empty, the failure mode is less graceful than=
=20
it could be: =E2=80=98Use of uninitialized value $zsig in scalar chomp=E2=
=80=99.
The while loop could be written more succinctly, if you=E2=80=99re into tha=
t kind=20
of thing.
my @lines =3D grep !(/^#/ || /^\s*$/), <FILE>;
Anders