Exforsys
+ Reply to Thread
Results 1 to 4 of 4

Perl Array :S

This is a discussion on Perl Array :S within the Perl forums, part of the Programming Talk category; I have an array which muliple values in it and what I wanted to do is add the 5th element ...

  1. #1
    JohnDoe is offline Junior Member Array
    Join Date
    Feb 2007
    Answers
    14

    Perl Array :S

    I have an array which muliple values in it and what I wanted to do is add the 5th element of the array to a new array which only stores unique values.

    I would normally do this in shell scripting but wanted to learn some Perl so any suggestions would be much appreciated,

    Thanks,


  2. #2
    sudipta82 is offline Junior Member Array
    Join Date
    Apr 2007
    Location
    INDIA
    Answers
    4
    Please post one example to help you out .


    Quote Originally Posted by JohnDoe View Post
    I have an array which muliple values in it and what I wanted to do is add the 5th element of the array to a new array which only stores unique values.

    I would normally do this in shell scripting but wanted to learn some Perl so any suggestions would be much appreciated,

    Thanks,



  3. #3
    sureshpillai is offline Junior Member Array
    Join Date
    Aug 2011
    Answers
    8
    Hi,
    Your question is not clear to me. If you need to make any change in middle of array, you can use "splice".

    Post your shell script here, so that I can give you proper perl solution.
    Thanks,
    Suresh


  4. #4
    Abdul_ali is offline Junior Member Array
    Join Date
    Dec 2011
    Answers
    4
    Hi,

    Please check out your answer. I hope your looking for this.

    @arr=(2,3,5,2,7,4,9,3,7,8,4,3,1);
    @new_arr=();
    $i=0;
    foreach(@arr)
    {
    $cValue=$_;
    if ($i=4)
    {
    if (grep(/^$cValue$/, @new_arr) == 0)
    {
    push(@new_arr,$_);
    }
    $i=0;
    }
    }
    print @arr;
    print "\n";
    print @new_arr;


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...