#1
  1. Web Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    480
    Rep Power
    112

    Question How to push double Array ?


    hello I want to know how to push Double Dimensional Array values?

    Code:
    #!/usr/bin/perl -w
    
    # For Single Array Pushing..
    push @single_arr, $values;
    
    # -- For Double Dimension Array pushing ??? ##
    push @single_arr[0], $values;
    How to push Double Dimension Array values?

    Thanks in advance
    I will try my best !!!
  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,251
    Rep Power
    1810
    You can push array references into an array:
    Code:
    #!/usr/bin/perl
    use strict;
    use warnings;
    use Data::Dumper;
    
    my @array;
    push @array, [qw/one two thee four/];
    or you can push values into a specific location in an array:
    Code:
    push @{$array[1]}, 'a value';
    push @{$array[2]}, [qw/five six/];
    print Dumper \@array;
    Result:
    Code:
    $VAR1 = [
              [
                'one',
                'two',
                'thee',
                'four'
              ],
              [
                'a value'
              ],
              [
                [
                  'five',
                  'six'
                ]
              ]
            ];
    Note: you can only push into specific array locations if those locations are undefined or already contain an array reference. Otherwise, you will have to make an assignment instead to overwrite the existing value.
  4. #3
  5. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2004
    Location
    Sunny Southern California
    Posts
    2,687
    Rep Power
    861
    to push into a multi-dimensional array:

    push @{$array_ref[0]},$values;

    but how you write the code depends on how your multi-dimensional array was originally created. If you used a reference to an array to begin with you would write it like this:

    push @{$array_ref->[1]},$values;
  6. #4
  7. Web Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    480
    Rep Power
    112

    Thumbs up


    Thanks a lot..
    all are working.. fine

    Thanks to all of them
    I will try my best !!!

IMN logo majestic logo threadwatch logo seochat tools logo