http://www.perlmonks.org?node_id=1134706


in reply to Re^2: Problem printing JSON type output
in thread Problem printing JSON type output

This seems to have solved my problem:

#!/usr/bin/perl $first=1; print "{"; print " \"data\":\n\t[\n"; my $filename = '/opt/scripts/bob_monitor.sh'; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; while (my $row = <$fh>) { chomp($row); for($row) { next if $row =~ /^cd|^#|^$|^,/; # skip lines ($bobinstance) = m/(bob(\d+))/; print ",\n" if not $first; $first = 0; $return = "\t{ \"{#BOBINSTANCE}\":\"$bobinstance\"}" u +nless /(^\s*$|^\,$)/; print $return; } } print "\t]\n"; print "}\n";
Thanks for the help.