array operations

L

Liang

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
 
J

Jürgen Exner

Liang said:
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
 
L

Liang

Thanks.

Liang

Jürgen Exner said:
Liang said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top