From 5ee9e0b72ab4c78de1ccc54b0bf982a91b915a11 Mon Sep 17 00:00:00 2001 From: fimojoha Date: Wed, 29 Apr 2015 16:03:35 +0200 Subject: Use 3-arg open, and check return values --- scripts/msg2notice.pl | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'scripts') diff --git a/scripts/msg2notice.pl b/scripts/msg2notice.pl index 33ddf3c..5dc3ba9 100644 --- a/scripts/msg2notice.pl +++ b/scripts/msg2notice.pl @@ -72,15 +72,18 @@ sub load_nicks { my($mask,$net,$channel,$flags,$flag); local(*FILE); - %nicks = (); - open FILE, "< $file"; - while () { - add_nick($_); - } - close FILE; - $count = keys %nicks; + %nicks = (); + if (open FILE, "<", $file) { + while () { + add_nick($_); + } + close FILE; + $count = keys %nicks; - crap("Loaded $count nicks"); + crap("Loaded $count nicks"); + } else { + crap("Unable to open $file for loading: $!"); + } } # --------[ save_nicks ]------------------------------------------------ @@ -93,15 +96,18 @@ sub save_nicks { return if $auto && !Irssi::settings_get_bool('msg2notice_autosave'); - open FILE, "> $file"; - for my $nick (keys %nicks) { - $count++; - print FILE "$nick\n"; - } - close FILE; + if (open FILE, ">", $file) { + for my $nick (keys %nicks) { + $count++; + print FILE "$nick\n"; + } + close FILE; - crap("Saved $count nicks to $file") - unless $auto; + crap("Saved $count nicks to $file") + unless $auto; + } else { + crap("Unable to open $file for saving: $!"); + } } # ======[ Hooks ]======================================================= -- cgit v1.2.3