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: Beginner:
moving an element out of many arrays

 



yaniv_av
Novice

Dec 30, 2002, 3:06 PM

Post #1 of 5 (440 views)
moving an element out of many arrays Can't Post

I have 3 arrays: A_tmp,B_tmp,C_tmp.
I want to move out all the occurance of the character "#" from those arrays.

I wrote this code. Can I do it shortly (maybe without creating 3 more arrays)?

foreach (@A_tmp) {
push (@A,$_) if ($_ ne "#");
}
foreach (@B_tmp) {
push (@B,$_) if ($_ ne "#");
}
foreach (@C_tmp) {
push (@C,$_) if ($_ ne "#");
}


thodi
stranger

Dec 31, 2002, 12:52 AM

Post #2 of 5 (436 views)
Re: [yaniv_av] moving an element out of many arrays [In reply to] Can't Post


In Reply To
I have 3 arrays: A_tmp,B_tmp,C_tmp.
I want to move out all the occurance of the character "#" from those arrays.

I wrote this code. Can I do it shortly (maybe without creating 3 more arrays)?


Code
@A_tmp = grep { $_ ne '#' } @A_tmp;



Paul
Enthusiast

Dec 31, 2002, 2:37 AM

Post #3 of 5 (433 views)
Re: [thodi] moving an element out of many arrays [In reply to] Can't Post

That's only using one array, I think you mean...


Code
@tmp = grep { $_ ne '#' } (@A_tmp, @B_tmp, @C_tmp);



thodi
stranger

Dec 31, 2002, 3:35 AM

Post #4 of 5 (430 views)
Re: [Paul] moving an element out of many arrays [In reply to] Can't Post


In Reply To
That's only using one array, I think you mean...

Code
@tmp = grep { $_ ne '#' } (@A_tmp, @B_tmp, @C_tmp);


No, I don't :-) Your solution leaves him with only one array afterwards, and the "source" arrays are unmodified. If that's what he wants -- fine, but I think he wants to keep his three arrays and just modify them in place.


Paul
Enthusiast

Dec 31, 2002, 6:26 AM

Post #5 of 5 (429 views)
Re: [thodi] moving an element out of many arrays [In reply to] Can't Post

>>
Can I do it shortly (maybe without creating 3 more arrays)?
<<

I took this to mean he only wanted one resulting array.

 
 


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

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