7 td-format - Print formatted lines per Tabular Data record
19 =item --nofield=[B<empty>|B<leave>|B<name>|B<skip-record>|B<fail>]
21 How to resolve non-existent field names in template variables?
27 Replace with empty string.
32 Leave the C<{field_name>}> string there unresolved.
36 Replace with the field name itself.
40 Don't output anything for the given record.
41 Continue with the next one.
45 Exit the program immediately with error code.
61 no if ($] >= 5.018), 'warnings' => 'experimental::smartmatch';
66 my $fieldname = shift;
67 my $template_fragment = shift;
68 my $callback_data = shift;
70 switch
($OptNoFieldBehavior)
72 case
('empty') { return ''; }
73 case
('leave') { return $template_fragment; }
74 case
('name') { return $fieldname; }
75 case
('skip-record') { $callback_data->{'skip-record'} = 1; die; }
76 case
('fail') { $callback_data->{'fail'} = 1; $callback_data->{'missing-field-name'} = $fieldname; die; }
84 my $callback_data = shift;
85 $s =~ s{\{([^{}]*)\}}{$fields->{$1} // replace_nofield
($1, $&, $callback_data)}eg
;
90 @NoFieldBehaviorValues = (qw
/empty leave name skip-record fail/);
91 $OptNoFieldBehavior = 'empty';
95 'nofield=s' => \
$OptNoFieldBehavior,
96 'n' => \
$OptNoNewline,
99 do '/usr/lib/tool/perl5/tabdata/common.pl' or die "$@";
101 pod2usage
(-exitval
=>2, -verbose
=>99) if not $OptNoFieldBehavior ~~ @NoFieldBehaviorValues;
107 process_header
(scalar <STDIN
>);
112 my @row = read_record
(\
*STDIN
);
113 my %fields = map {( $_ => $row[$Header{$_}] )} keys %Header;
114 my $callback_data = {};
117 $output = join $FS, map {render
($_, \
%fields, $callback_data)} @Templates; 1;
120 if($callback_data->{'skip-record'}) { next RECORD
; }
121 if($callback_data->{'fail'}) { die sprintf "%s: no such field: %s\n", $0, $callback_data->{'missing-field-name'}; }
123 $output .= $RS unless $OptNoNewline;