Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Could we from now on agree not to talk about (non)existing array elements,

Well we have an exists function, why shouldn't we talk about (non)existing array elements? :-)

Existence is an an important point to describe the behaviors of slicing, i.e. mostly returning undef for non-existing elements. (And I think what ikegami meant)

Let's express it in LRTs (Lanx's Rule of Thumb ;-)

1. Arrayslices (and hashslices) always return values for all requested elements. Not existing elements are represented as 'undef'.

DB<1> @a=1..2 DB<2> x @a[0,1] 0 1 1 2 DB<3> x @a[0,3] 0 1 1 undef DB<4> x @a[2,3] 0 undef 1 undef DB<5> @a=() DB<6> x @a[1,2] 0 undef 1 undef
2. Listlices work alike if and only if at least one of the requested elements exists. Otherwise it returns an empty list.

DB<5> x (1,2)[0,1] 0 1 1 2 DB<6> x (1,2)[0,3] 0 1 1 undef DB<7> x (1,2)[2,3] # DIFFERENT! empty array DB<8> x ()[0..3] # DIFFERENT! empty array DB<9> x (undef,undef)[0,2] 0 undef 1 undef

Note: Maybe the x command in the debugger should better say "empty list" instead of "empty array"....

Please correct me if I missed something with this "model" of slice behavior.

Cheers Rolf


In reply to Re^9: Array/List Strangeness by LanX
in thread Array/List Strangeness by Manchego

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-20 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found