Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: But I want null values in my array

by Fletch (Chancellor)
on Mar 11, 2020 at 19:05 UTC ( #11114141=note: print w/replies, xml ) Need Help??


in reply to But I want null values in my array

You need to give split an explicit special limit of -1 something negative if you want trailing empty fields to be returned. The relevant bit of the doc is below:

If LIMIT is omitted (or, equivalently, zero), then it i +s usually treated as if it were instead negative but with + the exception that trailing empty fields are stripped (empt +y leading fields are always preserved); if all fields are + empty, then all fields are considered to be trailing (and are +thus stripped in this case). Thus, the following: print join(':', split(',', 'a,b,c,,,')), "\n"; produces the output 'a:b:c', but the following: print join(':', split(',', 'a,b,c,,,', -1)), "\n"; produces the output 'a:b:c:::'.

Edit: tweaked wording.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11114141]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2020-06-01 16:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (3 votes). Check out past polls.

    Notices?