Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Perl array delete

by CountZero (Bishop)
on Apr 06, 2011 at 06:11 UTC ( [id://897667]=note: print w/replies, xml ) Need Help??


in reply to Perl array delete

If you think it through, deleteing an array element is a somewhat strange concept, except for the highest numbered element.

Think of an array as an apartment building. You may empty a single floor (set the value of the array-element to zero or the empty string) or even erase all traces of its former occupants (set the value of the aray element to undef), but you cannot take the floor itself away. That would really confuse all tenants living above it! When they arrive home in the evening, they would find their apartment having dropped one level. If you have a fifth floor in your building, you must have all the lower numbered floors (zero to four) as well.

In other words, as long as there are still array elements with an higher index, you cannot delete the lower numbered ones without fundamentally changing the structure of the array itself.

PS: Of course functions like pop, push, shift, unshift do change the structure of the array, but only from the top or bottom end.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: Perl array delete
by anu_1 (Acolyte) on Apr 06, 2011 at 06:32 UTC
    Thanks for your reply I am confused as it is working in Linux but not in the Solaris...

      Which versions of Perl are you using on those two machines?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-24 11:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found