[dns-operations] creeping poorness of judgement

Viktor Dukhovni ietf-dane at dukhovni.org
Tue Mar 17 01:46:27 UTC 2020


On Tue, Mar 17, 2020 at 01:21:30AM +0000, Paul Vixie wrote:
> On Tuesday, 17 March 2020 00:15:03 UTC Mark Andrews wrote:
> > I’d call that bad documentation.
> 
> documentation looks right to me.
> 
> > [util.redbarn:amd64] cat -n xxx.pl
> > 1  use Net::DNS;
> > 2  print $Net::DNS::VERSION . "\n";
> > 3  $rr = new Net::DNS::RR( name    => 'name',
> > 4          type    => 'TXT',
> > 5          txtdata => [ 'multiple', 'strings', 'string with spaces' ]
> > 6  );
> > 7  $_ = $rr->txtdata;
> > 8  print "{$_}\n";
> > [util.redbarn:amd64] perl xxx.pl
> > 1.21
> > {multiple strings string with spaces}

Yes, the txtdata() method concatenates with spaces in a scalar context.

    $ /tmp/txt.pl
    1.2
    name.   IN      TXT     multiple strings "string with spaces"
    multiple strings string with spaces

    $ cat /tmp/txt.pl
    #! /usr/bin/env perl
    use strict;
    use warnings;
    use Net::DNS;
    print $Net::DNS::VERSION . "\n";
    my $rr = new Net::DNS::RR ( name    => 'name'
                              , type    => 'TXT'
                              , txtdata => [ 'multiple', 'strings', 'string with spaces' ]
                              );
    $rr->print;
    my $data = $rr->txtdata;
    print $data,"\n";

This is also what Perl does when interpolating arrays into strings,
rather than explicitly calling join(), where the separator is explicitly
chosen:

    $ perl -le '@foo=(1,2,3); print "@foo\n";'
    1 2 3

The actual txtdata() function explicitly uses join(' ', ...): 

    sub txtdata {
            my $self = shift;
            $self->{txtdata} = [map Net::DNS::Text->new($_), @_] if scalar @_;
            my $txtdata = $self->{txtdata} || [];
            return ( map $_->value, @$txtdata ) if wantarray;
            join ' ', map $_->value, @$txtdata if defined wantarray;
    }

While it does present a case that lines up with Paul's preferred
semantics, I don't find the Net::DNS txtdata() behaviour in scalar
contexts either normative or particularly compelling. :-(

-- 
    Viktor.


More information about the dns-operations mailing list