Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to differentiate an empty array from an unitialized one?

by jwkrahn (Abbot)
on Jul 08, 2018 at 23:54 UTC ( [id://1218129]=note: print w/replies, xml ) Need Help??


in reply to How to differentiate an empty array from an unitialized one?

Note also that split only returns strings, it does not return "undefined elements".

Replies are listed 'Best First'.
Re^2: How to differentiate an empty array from an unitialized one?
by Anonymous Monk on Jul 09, 2018 at 08:07 UTC
    Iirc Split can return undef depending on regex capture groups
      Split can return undef depending on regex capture groups

      Yes, that's correct, for example split( /(x)|(y)/, "axbyc" ) yields ("a", "x", undef, "b", undef, "y", "c"). It's also documented at the bottom of split.

Re^2: How to differentiate an empty array from an unitialized one?
by Anonymous Monk on Jul 09, 2018 at 03:57 UTC
    Indeed, it would be incorrect for Perl to consider an uninitialized value to be an empty string, for much the same reason why, in SQL, NULL is not an empty string.
      it would be incorrect for Perl to consider an uninitialized value to be an empty string

      That is quite incorrect. Perl's undef (the default value for uninitialized scalars) evaluates to an empty string (or zero in numeric context). If warnings are enabled, this will usually warn, but only to indicate that the programmer may have made a mistake, not because it's inherently wrong.

      Perl does exactly that... The question isnt about arrays

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found