469,643 Members | 1,452 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

array operations

Hi,

I'm new to perl. I want to operate array in this way:
a). remove one item in an array. For example, @array=(1,3,2,4), and want to
remove the 2nd item '3'-- @array=(1,2,4);
b). find the difference of two arrays. For example,
@a1=(1,3,4);@a2=(1,2,4,5); want to get @a2_new=(all items in @a2, but not in
@a1)=(2,5);

Does any one know how to write the scripte?
Thanks in advance, and happy new year!
Liang
Jul 19 '05 #1
2 8679
Liang wrote:
I'm new to perl. I want to operate array in this way:
a). remove one item in an array. For example, @array=(1,3,2,4), and
want to remove the 2nd item '3'-- @array=(1,2,4);
Your specification is not quite clear. It can be interpreted in at least two
different ways:
- Do you want to remove the second element of an array? Then please see
"perldoc -f splice"
- Or do you want to remove the element with the value 3? Then please see
"perldoc -f grep"
b). find the difference of two arrays. For example,
@a1=(1,3,4);@a2=(1,2,4,5); want to get @a2_new=(all items in @a2, but
not in @a1)=(2,5);


That Question is Asked Frequently, please see "perldoc -q difference":
" How do I compute the difference of two arrays? [...]"

jue
Jul 19 '05 #2
Thanks.

Liang

"Jürgen Exner" <ju******@hotmail.com> wrote in message
news:AV*****************@nwrddc03.gnilink.net...
Liang wrote:
I'm new to perl. I want to operate array in this way:
a). remove one item in an array. For example, @array=(1,3,2,4), and
want to remove the 2nd item '3'-- @array=(1,2,4);
Your specification is not quite clear. It can be interpreted in at least

two different ways:
- Do you want to remove the second element of an array? Then please see
"perldoc -f splice"
- Or do you want to remove the element with the value 3? Then please see
"perldoc -f grep"
b). find the difference of two arrays. For example,
@a1=(1,3,4);@a2=(1,2,4,5); want to get @a2_new=(all items in @a2, but
not in @a1)=(2,5);


That Question is Asked Frequently, please see "perldoc -q difference":
" How do I compute the difference of two arrays? [...]"

jue

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Jeevan | last post: by
204 posts views Thread by Alexei A. Frounze | last post: by
4 posts views Thread by Peter | last post: by
3 posts views Thread by Lars Grobe | last post: by
49 posts views Thread by vfunc | last post: by
272 posts views Thread by Peter Olcott | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.