Help for this page

Select Code to Download


  1. or download this
    sub safe_print {
        for my $item (@_) {
            print defined $item ? $item : '[undef]';
        }
    }
    
  2. or download this
    sub safe_print {
        local $_;
        print map { defined $_ ? $_ : '[UNDEF]' } @_;
    }
    
  3. or download this
    use strict;
    use warnings;
    ...
        print $fh (map { defined $_ ? $_ : '[UNDEF]' } @_);
    }
    1;
    
  4. or download this
    
    open my $fh, ">", "foo" or die "Can't open foo: $!\n";
    my $printer = SafePrinter->new({fh => $fh});
    $printer->print("so it goes", undef, 'and it went', "\n");
    
  5. or download this