It's not entirely clear to me quite what you want. However, here's an SSCCE showing one way to avoid processing the undef values.
use strict; use warnings; use feature 'say'; use Test::More tests => 2; use Test::NoWarnings; my %foo = ( a => 1, b => 0, c => '', d => undef ); my $lined = ''; foreach my $opt (sort keys %foo) { unless (defined $opt && defined $foo{$opt}) { no warnings 'uninitialized'; say '9809 ', join '|', $opt, $foo{$opt}; next; } # Only run these if $foo{$opt} is defined; $foo{$opt} =~ s/[^[:ascii:]]//gxms; $lined .= join ("\t", $opt, $foo{$opt})."\n"; } is $lined, "a\t1\nb\t0\nc\t\n";
Note that your indentation is rather misleading and you haven't closed the outer loop. I've removed that outer loop here for simplicity.
In reply to Re: defined and value is 0
by hippo
in thread defined and value is 0
by redtux
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |