CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Whats wrong in here ?

 



yotam_k
Deleted

Jun 7, 2001, 8:39 AM

Post #1 of 4 (535 views)
Whats wrong in here ? Can't Post

delete $categories[$IdX];
It's refering to @categories which were opened before this apears and also $IdX was definded , I'v also rtyied to delete $categories[o]; and it didnt work , whats the problem??????



mhx
Enthusiast / Moderator

Jun 7, 2001, 12:11 PM

Post #2 of 4 (531 views)
Re: Whats wrong in here ? [In reply to] Can't Post

delete is for hash tables, not for arrays. To delete elements from an array, use the splice function:

Code
my $idx = 5; 
my @ary = (0,1,2,3,4,5,6,7,8,9);
splice @ary, $idx, 1;
# now, @ary is (0,1,2,3,4,6,7,8,9)

-- Marcus



yotam_k
Deleted

Jun 11, 2001, 3:47 AM

Post #3 of 4 (508 views)
Re: Whats wrong in here ? [In reply to] Can't Post

Thanx man it's workes great but why there is a 1; in the end? why not just ;?
is it another why of writing it :
splice @ary, $idx;
?




wickedxter
User

Jun 11, 2001, 10:58 AM

Post #4 of 4 (506 views)
Re: Whats wrong in here ? [In reply to] Can't Post

the reason why you need the 1 at the end is the length.

splice syntax:
splice(array, skipelements, length);

length is the number of elements to re replaced.

this should help you understand why.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives