array operations

Discussion in 'Perl' started by Liang, Dec 31, 2003.

  1. Liang

    Liang Guest

    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
     
    Liang, Dec 31, 2003
    #1
    1. Advertising

  2. 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
     
    Jürgen Exner, Dec 31, 2003
    #2
    1. Advertising

  3. Liang

    Liang Guest

    Thanks.

    Liang

    "Jürgen Exner" <> wrote in message
    news:AVwIb.7423$...
    > 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
    >
    >
     
    Liang, Jan 5, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jesus M. Salvo Jr.
    Replies:
    2
    Views:
    4,252
    robert
    Feb 11, 2006
  2. Chris
    Replies:
    6
    Views:
    2,413
    Daniel Pitts
    Jan 5, 2007
  3. Replies:
    12
    Views:
    523
    santosh
    Nov 15, 2006
  4. Replies:
    3
    Views:
    777
    Terry Reedy
    Apr 1, 2011
  5. Ferenc Engard

    array operations

    Ferenc Engard, Dec 26, 2003, in forum: Ruby
    Replies:
    3
    Views:
    96
    Ferenc Engard
    Dec 27, 2003
Loading...

Share This Page