develooper Front page | perl.perl5.porters | Postings from January 2019

[perl #133781] Clarify DOC for split. Section about splitting emptystring

Thread Next
From:
James E Keenan via RT
Date:
January 19, 2019 13:44
Subject:
[perl #133781] Clarify DOC for split. Section about splitting emptystring
Message ID:
rt-4.0.24-14390-1547905447-930.133781-15-0@perl.org
On Sat, 19 Jan 2019 03:35:40 GMT, kes-kes@yandex.ru wrote:
> Hi.
> 
> > Note that splitting an EXPR that evaluates to the empty string always
> > produces zero fields, regardless of the LIMIT specified.
> 
> Please clarify what 'zero fields' mean. Is this empty string or
> undefined value?
> 
> print map{ defined? "YES" :"NO"} split('b', "bd"); # YESYES
> 
> print map{ defined? "YES" :"NO"} split('b', "b"); # NOTHING IS PRINTED
> 
> print map{ defined? "YES" :"NO"} split('b', ""); # NOTHING IS PRINTED
> 
> 
> would it be better to say:
> 
> > Note that splitting an EXPR that evaluates to the empty string does
> > not produce fields at all, regardless of the LIMIT specified.

I think you're getting confused by your example.

The documentation for 'split' states that it:

#####
Splits the string EXPR into a list of strings and returns the list in list context, or the size of the list in scalar context.
#####

So by prepending the 'split' with a 'map', you're requesting list context.

You then call 'defined' on the return value of 'split', i.e., you are calling 'defined' on a list.  The documentation for 'defined' states:

#####
Returns a Boolean value telling whether EXPR has a value other than the undefined value "undef". If EXPR is not present, $_ is checked.
#####

But the lists returned in your second and third examples are empty lists.  In those cases, it seems to me that there is no 'EXPR' or $_ on which to call 'defined'.  So the 'defined' has nothing to do.

See example attached.  I think the existing documentation for 'split' is satisfactory in this regard.  I don't see a case for changing it.

Thank you very much.
-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=133781

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About