--- trunk/lib/WebPAC/Normalize.pm 2006/04/30 12:17:19 436 +++ trunk/lib/WebPAC/Normalize.pm 2006/06/26 16:39:51 536 @@ -1,789 +1,342 @@ package WebPAC::Normalize; +use Exporter 'import'; +@EXPORT = qw/ + set_rec set_lookup + get_ds clean_ds + tag search display + rec1 rec2 rec + regex prefix suffix surround + first lookup join_with +/; use warnings; use strict; -use blib; -use WebPAC::Common; -use base 'WebPAC::Common'; + +#use base qw/WebPAC::Common/; use Data::Dumper; =head1 NAME -WebPAC::Normalize - data mungling for normalisation +WebPAC::Normalize - describe normalisaton rules using sets =head1 VERSION -Version 0.09 +Version 0.04 =cut -our $VERSION = '0.09'; +our $VERSION = '0.04'; =head1 SYNOPSIS -This package contains code that mungle data to produce normalized format. - -It contains several assumptions: - -=over - -=item * - -format of fields is defined using C notation for repeatable fields -or C for single (or first) value, where C<123> is field number and -C is subfield. - -=item * - -source data records (C<$rec>) have unique identifiers in field C<000> - -=item * - -optional C tag at B will be -perl code that is evaluated before producing output (value of field will be -interpolated before that) - -=item * - -optional C at B will apply perl -code defined as code ref on format after field substitution to producing -output - -There is one built-in filter called C which can be use like this: - - filter{regex(s/foo/bar/)} - -=item * - -optional C will be then performed. See C. - -=item * - -at end, optional Cs rules are resolved. Format rules are similar to -C and can also contain C which is performed after -values are inserted in format. - -=back - -This also describes order in which transformations are applied (eval, -filter, lookup, format) which is important to undestand when deciding how to -solve your data mungling and normalisation process. - - +This module uses C files to perform normalisation +from input records using perl functions which are specialized for set +processing. + +Sets are implemented as arrays, and normalisation file is valid perl, which +means that you check it's validity before running WebPAC using +C. +Normalisation can generate multiple output normalized data. For now, supported output +types (on the left side of definition) are: C, C and C. =head1 FUNCTIONS -=head2 new +=head2 data_structure -Create new normalisation object +Return data structure - my $n = new WebPAC::Normalize::Something( - filter => { - 'filter_name_1' => sub { - # filter code - return length($_); - }, ... - }, - db => $db_obj, - lookup_regex => $lookup->regex, - lookup => $lookup_obj, - prefix => 'foobar', + my $ds = WebPAC::Normalize( + lookup => $lookup->lookup_hash, + row => $row, + rules => $normalize_pl_config, ); -Parametar C defines user supplied snippets of perl code which can -be use with C notation. - -C is used to form filename for database record (to support multiple -source files which are joined in one database). - -Recommended parametar C is used to enable parsing of lookups -in structures. If you pass this parametar, you must also pass C -which is C object. +This function will B if normalizastion can't be evaled. =cut -sub new { - my $class = shift; - my $self = {@_}; - bless($self, $class); - - my $r = $self->{'lookup_regex'} ? 1 : 0; - my $l = $self->{'lookup'} ? 1 : 0; - - my $log = $self->_get_logger(); - - # those two must be in pair - if ( ($r & $l) != ($r || $l) ) { - my $log = $self->_get_logger(); - $log->logdie("lookup_regex and lookup must be in pair"); - } - - $log->logdie("lookup must be WebPAC::Lookup object") if ($self->{'lookup'} && ! $self->{'lookup'}->isa('WebPAC::Lookup')); - - $log->warn("no prefix defined. please check that!") unless ($self->{'prefix'}); - - $log->debug("using lookup regex: ", $self->{lookup_regex}) if ($r && $l); +sub data_structure { + my $arg = {@_}; - if (! $self->{filter} || ! $self->{filter}->{regex}) { - $log->debug("adding built-in filter regex"); - $self->{filter}->{regex} = sub { - my ($val, $regex) = @_; - eval "\$val =~ $regex"; - return $val; - }; - } + die "need row argument" unless ($arg->{row}); + die "need normalisation argument" unless ($arg->{rules}); - $self ? return $self : return undef; + no strict 'subs'; + set_lookup( $arg->{lookup} ); + set_rec( $arg->{row} ); + clean_ds(); + eval "$arg->{rules}"; + die "error evaling $arg->{rules}: $@\n" if ($@); + return get_ds(); } -=head2 all_tags +=head2 set_rec -Returns all tags in document in specified order +Set current record hash - my $sorted_tags = $self->all_tags(); + set_rec( $rec ); =cut -sub all_tags { - my $self = shift; - - if (! $self->{_tags_by_order}) { - - my $log = $self->_get_logger; - # sanity check - $log->logdie("can't find self->{inport_xml}->{indexer}") unless ($self->{import_xml}->{indexer}); - - my @tags = keys %{ $self->{'import_xml'}->{'indexer'}}; - $log->debug("unsorted tags: " . join(", ", @tags)); +my $rec; - @tags = sort { $self->_sort_by_order } @tags; - - $log->debug("sorted tags: " . join(",", @tags) ); - - $self->{_tags_by_order} = \@tags; - } - - return $self->{_tags_by_order}; +sub set_rec { + $rec = shift or die "no record hash"; } +=head2 tag +Define new tag for I and I. -=head2 data_structure - -Create in-memory data structure which represents normalized layout from -C. + tag('Title', rec('200','a') ); -This structures are used to produce output. - - my $ds = $webpac->data_structure($rec); =cut -sub data_structure { - my $self = shift; - - my $log = $self->_get_logger(); - - my $rec = shift; - $log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); - - $log->debug("data_structure rec = ", sub { Dumper($rec) }); - - $log->logdie("need unique ID (mfn) in field 000 of record " . Dumper($rec) ) unless (defined($rec->{'000'})); - - my $id = $rec->{'000'}->[0] || $log->logdie("field 000 isn't array!"); - - my $cache_file; - - if ($self->{'db'}) { - my $ds = $self->{'db'}->load_ds( id => $id, prefix => $self->{prefix} ); - $log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper($ds) }); - return $ds if ($ds); - $log->debug("cache miss, creating"); - } - - my $tags = $self->all_tags(); - - $log->debug("tags: ",sub { join(", ",@{ $tags }) }); - - my $ds; - - foreach my $field (@{ $tags }) { - - my $row; - -#print "field $field [",$self->{'tag'},"] = ",Dumper($self->{'import_xml'}->{'indexer'}->{$field}->{$self->{'tag'}}); - - foreach my $tag (@{$self->{'import_xml'}->{'indexer'}->{$field}->{$self->{'tag'}}}) { - my $format; - - $log->logdie("expected tag HASH and got $tag") unless (ref($tag) eq 'HASH'); - $format = $tag->{'value'} || $tag->{'content'}; - - my @v; - if ($self->{'lookup_regex'} && $format =~ $self->{'lookup_regex'}) { - @v = $self->_rec_to_arr($rec,$format,'fill_in'); - } else { - @v = $self->_rec_to_arr($rec,$format,'parse'); - } - if (! @v) { - $log->debug("$field <",$self->{tag},"> format: $format no values"); - next; - } else { - $log->debug("$field <",$self->{tag},"> format: $format values: ", join(",", @v)); - } - - if ($tag->{'sort'}) { - @v = $self->sort_arr(@v); - } - - # use format? - if ($tag->{'format_name'}) { - @v = map { $self->apply_format($tag->{'format_name'},$tag->{'format_delimiter'},$_) } @v; - } - - # delimiter will join repeatable fields - if ($tag->{'delimiter'}) { - @v = ( join($tag->{'delimiter'}, @v) ); - } - - # default types - my @types = qw(display search); - # override by type attribute - @types = ( $tag->{'type'} ) if ($tag->{'type'}); - - foreach my $type (@types) { - # append to previous line? - $log->debug("tag $field / $type [",sub { join(",",@v) }, "] ", $row->{'append'} || 'no append'); - if ($tag->{'append'}) { - - # I will delimit appended part with - # delimiter (or ,) - my $d = $tag->{'delimiter'}; - # default delimiter - $d ||= " "; - - my $last = pop @{$row->{$type}}; - $d = "" if (! $last); - $last .= $d . join($d, @v); - push @{$row->{$type}}, $last; - - } else { - push @{$row->{$type}}, @v; - } - } - - - } - - if ($row) { - $row->{'tag'} = $field; - - # TODO: name_sigular, name_plural - my $name = $self->{'import_xml'}->{'indexer'}->{$field}->{'name'}; - my $row_name = $name ? $self->_x($name) : $field; - - # post-sort all values in field - if ($self->{'import_xml'}->{'indexer'}->{$field}->{'sort'}) { - $log->warn("sort at field tag not implemented"); - } - - $ds->{$row_name} = $row; - - $log->debug("row $field: ",sub { Dumper($row) }); - } - - } - - $self->{'db'}->save_ds( - id => $id, - ds => $ds, - prefix => $self->{prefix}, - ) if ($self->{'db'}); - - $log->debug("ds: ", sub { Dumper($ds) }); - - $log->logconfess("data structure returned is not array any more!") if wantarray; - - return $ds; +my $out; +sub tag { + my $name = shift or die "tag needs name as first argument"; + my @o = grep { defined($_) && $_ ne '' } @_; + return unless (@o); + $out->{$name}->{tag} = $name; + $out->{$name}->{search} = \@o; + $out->{$name}->{display} = \@o; } -=head2 parse - -Perform smart parsing of string, skipping delimiters for fields which aren't -defined. It can also eval code in format starting with C and -return output or nothing depending on eval code. - - my $text = $webpac->parse($rec,'eval{"v901^a" eq "Deskriptor"}descriptor: v250^a', $i); - -Filters are implemented here. While simple form of filters looks like this: +=head2 display - filter{name_of_filter} +Define tag just for I -but, filters can also have variable number of parametars like this: - - filter{name_of_filter(param,param,param)} + @v = display('Title', rec('200','a') ); =cut -my $warn_once; - -sub parse { - my $self = shift; - - my ($rec, $format_utf8, $i, $rec_size) = @_; - - return if (! $format_utf8); - - my $log = $self->_get_logger(); - - $log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); - - $i = 0 if (! $i); - - my $format = $self->_x($format_utf8) || $log->logconfess("can't convert '$format_utf8' from UTF-8 to ",$self->{'code_page'}); - - my @out; - - $log->debug("format: $format [$i]"); - - my $eval_code; - # remove eval{...} from beginning - $eval_code = $1 if ($format =~ s/^eval{([^}]+)}//s); - - my $filter_name; - # remove filter{...} from beginning - $filter_name = $1 if ($format =~ s/^filter{([^}]+)}//s); - - # did we found any (att all) field from format in row? - my $found_any; - # prefix before first field which we preserve it $found_any - my $prefix; - - my $f_step = 1; - - while ($format =~ s/^(.*?)(v|s)(\d+)(?:\^(\w))?//s) { - - my $del = $1 || ''; - $prefix = $del if ($f_step == 1); - - my $fld_type = lc($2); - - # repeatable index - my $r = $i; - if ($fld_type eq 's') { - if ($found_any->{'v'}) { - $r = 0; - } else { - return; - } - } +sub display { + my $name = shift or die "display needs name as first argument"; + my @o = grep { defined($_) && $_ ne '' } @_; + return unless (@o); + $out->{$name}->{tag} = $name; + $out->{$name}->{display} = \@o; +} - my $found = 0; - my $tmp = $self->get_data(\$rec,$3,$4,$r,\$found,$rec_size); +=head2 search - if ($found) { - $found_any->{$fld_type} += $found; +Prepare values just for I - # we will skip delimiter before first occurence of field! - push @out, $del unless($found_any->{$fld_type} == 1); - push @out, $tmp if ($tmp); - } - $f_step++; - } + @v = search('Title', rec('200','a') ); - # test if any fields found? - return if (! $found_any->{'v'} && ! $found_any->{'s'}); +=cut - my $out = join('',@out); +sub search { + my $name = shift or die "search needs name as first argument"; + my @o = grep { defined($_) && $_ ne '' } @_; + return unless (@o); + $out->{$name}->{tag} = $name; + $out->{$name}->{search} = \@o; +} - if ($out) { - # add rest of format (suffix) - $out .= $format; +=head2 get_ds - # add prefix if not there - $out = $prefix . $out if ($out !~ m/^\Q$prefix\E/); +Return hash formatted as data structure - $log->debug("result: $out"); - } + my $ds = get_ds(); - if ($eval_code) { - my $eval = $self->fill_in($rec,$eval_code,$i) || return; - $log->debug("about to eval{$eval} format: $out"); - return if (! $self->_eval($eval)); - } - - if ($filter_name) { - my @filter_args; - if ($filter_name =~ s/(\w+)\((.*)\)/$1/) { - @filter_args = split(/,/, $2); - } - if ($self->{'filter'}->{$filter_name}) { - $log->debug("about to filter{$filter_name} format: $out with arguments: ", join(",", @filter_args)); - unshift @filter_args, $out; - $out = $self->{'filter'}->{$filter_name}->(@filter_args); - return unless(defined($out)); - $log->debug("filter result: $out"); - } elsif (! $warn_once->{$filter_name}) { - $log->warn("trying to use undefined filter $filter_name"); - $warn_once->{$filter_name}++; - } - } +=cut +sub get_ds { return $out; } -=head2 fill_in +=head2 clean_ds -Workhourse of all: takes record from in-memory structure of database and -strings with placeholders and returns string or array of with substituted -values from record. +Clean data structure hash for next record - my $text = $webpac->fill_in($rec,'v250^a'); + clean_ds(); -Optional argument is ordinal number for repeatable fields. By default, -it's assume to be first repeatable field (fields are perl array, so first -element is 0). -Following example will read second value from repeatable field. - - my $text = $webpac->fill_in($rec,'Title: v250^a',1); +=cut -This function B perform parsing of format to inteligenty skip -delimiters before fields which aren't used. +sub clean_ds { + $out = undef; +} -This method will automatically decode UTF-8 string to local code page -if needed. +=head2 set_lookup -There is optional parametar C<$record_size> which can be used to get sizes of -all C combinations in this format. +Set current lookup hash - my $text = $webpac->fill_in($rec,'got: v900^a v900^x',0,\$rec_size); + set_lookup( $lookup ); =cut -sub fill_in { - my $self = shift; - - my $log = $self->_get_logger(); - - my ($rec,$format,$i,$rec_size) = @_; - - $log->logconfess("need data record") unless ($rec); - $log->logconfess("need format to parse") unless($format); +my $lookup; - # iteration (for repeatable fields) - $i ||= 0; +sub set_lookup { + $lookup = shift; +} - $log->logdie("infitite loop in format $format") if ($i > ($self->{'max_mfn'} || 9999)); +=head2 rec1 - # FIXME remove for speedup? - $log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); +Return all values in some field - if (utf8::is_utf8($format)) { - $format = $self->_x($format); - } + @v = rec1('200') - my $found = 0; - my $just_single = 1; +TODO: order of values is probably same as in source data, need to investigate that - my $eval_code; - # remove eval{...} from beginning - $eval_code = $1 if ($format =~ s/^eval{([^}]+)}//s); - - my $filter_name; - # remove filter{...} from beginning - $filter_name = $1 if ($format =~ s/^filter{([^}]+)}//s); - - { - # fix warnings - no warnings 'uninitialized'; - - # do actual replacement of placeholders - # repeatable fields - if ($format =~ s/v(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,$i,\$found,$rec_size)/ges) { - $just_single = 0; - } - - # non-repeatable fields - if ($format =~ s/s(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,0,\$found,$rec_size)/ges) { - return if ($i > 0 && $just_single); - } - } +=cut - if ($found) { - $log->debug("format: $format"); - if ($eval_code) { - my $eval = $self->fill_in($rec,$eval_code,$i); - return if (! $self->_eval($eval)); - } - if ($filter_name && $self->{'filter'}->{$filter_name}) { - $log->debug("filter '$filter_name' for $format"); - $format = $self->{'filter'}->{$filter_name}->($format); - return unless(defined($format)); - $log->debug("filter result: $format"); - } - # do we have lookups? - if ($self->{'lookup'}) { - if ($self->{'lookup'}->can('lookup')) { - my @lookup = $self->{lookup}->lookup($format); - $log->debug("lookup $format", join(", ", @lookup)); - return @lookup; +sub rec1 { + my $f = shift; + return unless (defined($rec) && defined($rec->{$f})); + if (ref($rec->{$f}) eq 'ARRAY') { + return map { + if (ref($_) eq 'HASH') { + values %{$_}; } else { - $log->warn("Have lookup object but can't invoke lookup method"); + $_; } - } else { - return $format; - } - } else { - return; + } @{ $rec->{$f} }; + } elsif( defined($rec->{$f}) ) { + return $rec->{$f}; } } +=head2 rec2 -=head2 _rec_to_arr - -Similar to C and C, but returns array of all repeatable fields. Usable -for fields which have lookups, so they shouldn't be parsed but rather -Cd or Ced. Last argument is name of operation: C or C. +Return all values in specific field and subfield - my @arr = $webpac->fill_in_to_arr($rec,'[v900];;[v250^a]','paste'); + @v = rec2('200','a') =cut -sub _rec_to_arr { - my $self = shift; - - my ($rec, $format_utf8, $code) = @_; +sub rec2 { + my $f = shift; + return unless (defined($rec && $rec->{$f})); + my $sf = shift; + return map { $_->{$sf} } grep { ref($_) eq 'HASH' && $_->{$sf} } @{ $rec->{$f} }; +} - my $log = $self->_get_logger(); +=head2 rec - $log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); - return if (! $format_utf8); +syntaxtic sugar for - $log->debug("using $code on $format_utf8"); + @v = rec('200') + @v = rec('200','a') - my $i = 0; - my $max = 0; - my @arr; - my $rec_size = {}; +=cut - while ($i <= $max) { - my @v = $self->$code($rec,$format_utf8,$i++,\$rec_size); - if ($rec_size) { - foreach my $f (keys %{ $rec_size }) { - $max = $rec_size->{$f} if ($rec_size->{$f} > $max); - } - $log->debug("max set to $max"); - undef $rec_size; - } - if (@v) { - push @arr, @v; - } else { - push @arr, '' if ($max > $i); - } +sub rec { + if ($#_ == 0) { + return rec1(@_); + } elsif ($#_ == 1) { + return rec2(@_); } - - $log->debug("format '$format_utf8' returned ",--$i," elements: ", sub { join(" | ",@arr) }) if (@arr); - - return @arr; } +=head2 regex -=head2 get_data - -Returns value from record. - - my $text = $self->get_data(\$rec,$f,$sf,$i,\$found,\$rec_size); - -Required arguments are: - -=over 8 - -=item C<$rec> +Apply regex to some or all values -record reference - -=item C<$f> - -field - -=item C<$sf> - -optional subfield - -=item C<$i> - -index offset for repeatable values ( 0 ... $rec_size->{'400^a'} ) - -=item C<$found> - -optional variable that will be incremeted if preset - -=item C<$rec_size> - -hash to hold maximum occurances of C combinations -(which can be accessed using keys in same format) - -=back - -Returns value or empty string, updates C<$found> and C -if present. + @v = regex( 's/foo/bar/g', @v ); =cut -sub get_data { - my $self = shift; - - my ($rec,$f,$sf,$i,$found,$cache) = @_; - - return '' unless ($$rec->{$f} && ref($$rec->{$f}) eq 'ARRAY'); - - if (defined($$cache)) { - $$cache->{ $f . ( $sf ? '^' . $sf : '' ) } ||= scalar @{ $$rec->{$f} }; - } - - return '' unless ($$rec->{$f}->[$i]); - - { - no strict 'refs'; - if (defined($sf)) { - $$found++ if (defined($$found) && $$rec->{$f}->[$i]->{$sf}); - return $$rec->{$f}->[$i]->{$sf}; - } else { - $$found++ if (defined($$found)); - # it still might have subfields, just - # not specified, so we'll dump some debug info - if ($$rec->{$f}->[$i] =~ /HASH/o) { - my $out; - foreach my $k (keys %{$$rec->{$f}->[$i]}) { - my $v = $$rec->{$f}->[$i]->{$k}; - $out .= '$' . $k .':' . $v if ($v); - } - return $out; - } else { - return $$rec->{$f}->[$i]; - } - } +sub regex { + my $r = shift; + my @out; + #warn "r: $r\n",Dumper(\@_); + foreach my $t (@_) { + next unless ($t); + eval "\$t =~ $r"; + push @out, $t if ($t && $t ne ''); } + return @out; } +=head2 prefix -=head2 apply_format +Prefix all values with a string -Apply format specified in tag with C and -C. - - my $text = $webpac->apply_format($format_name,$format_delimiter,$data); - -Formats can contain C if you need them. + @v = prefix( 'my_', @v ); =cut -sub apply_format { - my $self = shift; - - my ($name,$delimiter,$data) = @_; - - my $log = $self->_get_logger(); - - if (! $self->{'import_xml'}->{'format'}->{$name}) { - $log->warn(" is not defined in ",$self->{'import_xml_file'}); - return $data; - } - - $log->warn("no delimiter for format $name") if (! $delimiter); +sub prefix { + my $p = shift or die "prefix needs string as first argument"; + return map { $p . $_ } grep { defined($_) } @_; +} - my $format = $self->_x($self->{'import_xml'}->{'format'}->{$name}->{'content'}) || $log->logdie("can't find format '$name'"); +=head2 suffix - my @data = split(/\Q$delimiter\E/, $data); +suffix all values with a string - my $out = sprintf($format, @data); - $log->debug("using format $name [$format] on $data to produce: $out"); + @v = suffix( '_my', @v ); - if ($self->{'lookup_regex'} && $out =~ $self->{'lookup_regex'}) { - return $self->{'lookup'}->lookup($out); - } else { - return $out; - } +=cut +sub suffix { + my $s = shift or die "suffix needs string as first argument"; + return map { $_ . $s } grep { defined($_) } @_; } -=head2 sort_arr +=head2 surround -Sort array ignoring case and html in data +surround all values with a two strings - my @sorted = $webpac->sort_arr(@unsorted); + @v = surround( 'prefix_', '_suffix', @v ); =cut -sub sort_arr { - my $self = shift; - - my $log = $self->_get_logger(); - - # FIXME add Schwartzian Transformation? - - my @sorted = sort { - $a =~ s#<[^>]+/*>##; - $b =~ s#<[^>]+/*>##; - lc($b) cmp lc($a) - } @_; - $log->debug("sorted values: ",sub { join(", ",@sorted) }); - - return @sorted; +sub surround { + my $p = shift or die "surround need prefix as first argument"; + my $s = shift or die "surround needs suffix as second argument"; + return map { $p . $_ . $s } grep { defined($_) } @_; } +=head2 first -=head1 INTERNAL METHODS +Return first element -=head2 _sort_by_order - -Sort xml tags data structure accoding to C attribute. + $v = first( @v ); =cut -sub _sort_by_order { - my $self = shift; - - my $va = $self->{'import_xml'}->{'indexer'}->{$a}->{'order'} || - $self->{'import_xml'}->{'indexer'}->{$a}; - my $vb = $self->{'import_xml'}->{'indexer'}->{$b}->{'order'} || - $self->{'import_xml'}->{'indexer'}->{$b}; - - return $va <=> $vb; +sub first { + my $r = shift; + return $r; } -=head2 _x +=head2 lookup -Convert strings from C encoding into application -specific encoding (optinally specified using C to C -constructor). +Consult lookup hashes for some value - my $text = $n->_x('normalize text string'); - -This is a stub so that other modules doesn't have to implement it. + @v = lookup( $v ); + @v = lookup( @v ); =cut -sub _x { - my $self = shift; - return shift; +sub lookup { + my $k = shift or return; + return unless (defined($lookup->{$k})); + if (ref($lookup->{$k}) eq 'ARRAY') { + return @{ $lookup->{$k} }; + } else { + return $lookup->{$k}; + } } +=head2 join_with -=head1 AUTHOR +Joins walues with some delimiter -Dobrica Pavlinusic, C<< >> - -=head1 COPYRIGHT & LICENSE - -Copyright 2005 Dobrica Pavlinusic, All Rights Reserved. - -This program is free software; you can redistribute it and/or modify it -under the same terms as Perl itself. + $v = join_with(", ", @v); =cut -1; # End of WebPAC::Normalize +sub join_with { + my $d = shift; + return join($d, grep { defined($_) && $_ ne '' } @_); +} + +# END +1;