From ee9b0f5cfc4eecb9c68880d5a6b4ea2e981f0df1 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 1 Oct 2017 16:18:55 +0200 Subject: Gracefully handle nonexistent files --- bin/mqtt-multipub | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/mqtt-multipub b/bin/mqtt-multipub index 4c9b2dc..c079d6f 100755 --- a/bin/mqtt-multipub +++ b/bin/mqtt-multipub @@ -14,8 +14,10 @@ my $mqtt = Net::MQTT::Simple->new( '172.23.225.193' ); sub parse_content_string { my ($raw_content) = @_; if ($raw_content =~ m{ ^ / [^/] }x) { - my $content = read_file($raw_content); - chomp $content; + my $content = read_file($raw_content, { err_mode => 'carp' }); + if (defined $content) { + chomp $content; + } return $content; } return $raw_content; -- cgit v1.2.3