Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^5: Array/List Strangeness

by jethro (Monsignor)
on Aug 05, 2009 at 10:00 UTC ( [id://786029]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Array/List Strangeness
in thread Array/List Strangeness

There is no such thing as a non-existing array element

Yes, there is. An array with 5 undef values in it has size 5 and not unlimited size. And concatenating two arrays works only because the first array is not unlimited

Replies are listed 'Best First'.
Re^6: Array/List Strangeness
by LanX (Saint) on Aug 05, 2009 at 11:12 UTC
    That's what Taulmarill meant.

    Basically: an "empty" array can have any size, but an empty list always has size 0.

    UPDATE: that should show it...

    DB<1> @a[3..5]=() DB<2> @b[3..5]=() DB<3> print scalar @a 6 DB<4> print ( () = @a,@b ) DB<5> @c= @a,@b DB<6> print scalar @c 6 DB<7> @c=(@a,@b) DB<8> print scalar @c 12 DB<9> print ( () = (@a,@b) ) DB<10> push @a,@b DB<11> print scalar @a 12 DB<12> x @a 0 undef 1 undef 2 undef 3 undef 4 undef 5 undef 6 undef 7 undef 8 undef 9 undef 10 undef 11 undef

    Line 12 clearly shows, that concatenating two "empty" arrays leads to a larger "empty" array...

    Anyway the difference between line 5 and 7 is somehow surprising ...

    UPDATE: Aaaaaargh!!! 8)

    In line 5, I fell into the scalar comma operator trap again ... it's basically (@c=@a),(@b)

    Cheers Rolf

      Well, Taulmarill was questioning Ikegamis words 'non-existing array element'. So I'm just pointing out that there is a real difference between non-existing array element and undef'd array element (even if we would wish otherwise to have more consistency).

      ++ for what you are saying after 'Basically:', an excellent description of the situation

        I admit that i might have misunderstood something here .... although i'm not sure what....

        Could we from now on agree not to talk about (non)existing array elements, but about elements <= $#array and elements > $#array. That might make things easier for my twisted, sleep deprived mind.

        update: also i'd like $[ to stay 0.
        ++ for what you are saying after 'Basically:', an excellent description of the situation

        Actually it should be defined what "empty" means. undef can be an existing element of a list!

        DB<1> p scalar ( ()=(undef,undef) ) 2

        Cheers Rolf

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-18 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found