Professional Web Applications Themes

Problem with storing data in an array - PERL Beginners

Hi, my sql query is select a,b .... and the code to store the results in stach is : my stach; while( my ary=$sth->fetchrow_array()) { push stach, [ary] ; } and this doesn't work if I look at stach there are only ARRAY(0x81cff60) in the two columns of stach. Can you help me plz? Thank you. Höstrusk och grå moln - köp en resa till solen på Yahoo! Resor på adressen http://se.docs./travel/index.html...

  1. #1

    Default Problem with storing data in an array

    Hi,

    my sql query is select a,b ....

    and the code to store the results in stach is :

    my stach;
    while( my ary=$sth->fetchrow_array()) {
    push stach, [ary] ;
    }

    and this doesn't work if I look at stach there are
    only ARRAY(0x81cff60) in the two columns of stach.

    Can you help me plz?

    Thank you.

    Höstrusk och grå moln - köp en resa till solen på Yahoo! Resor på adressen http://se.docs./travel/index.html
    Romain Guest

  2. #2

    Default Re: Problem with storing data in an array

    On 4/7/2004 5:45 PM, Romain Groleau wrote:
     

    my stach;
    while(my ary = $sth->fetchrow_array()) {
    push stach, \ary;
    }

    use Data::Dumper;
    print Dumper(\stach);


    Randy Guest

  3. #3

    Default Re: Problem with storing data in an array



    Romain Groleau wrote:
     

    Howdy
     
    [ary] if a reference just like \ary

    you could do the same thing by doing:

    for( { $dbh->selectall_arrayref($query) } ) {

    my ($a_column,$b_column) = { $_ };

    }

    And all that without having to do the prepare, execute, getchrow_array
    dance or worry about array names and simplifying the process of
    processing the data :)

    HTH

    Lee.M - JupiterHost.Net
     
    Jupiterhost.Net Guest

  4. #4

    Default Re: Problem with storing data in an array

    On 4/7/2004 5:50 PM, Randy W. Sims wrote:
     
    >
    >
    > my stach;
    > while(my ary = $sth->fetchrow_array()) {
    > push stach, \ary;
    > }
    >
    > use Data::Dumper;
    > print Dumper(\stach);[/ref]

    Oops, sent that too soon.

    In perl, a multidimensional array is an array of arrays, i.e. one array
    holds an array in each slot.

    Imagine an array with 3 slots. (where a slot is represented by [])

    a=
    []
    []
    []

    Now imagine that each slot holds a reference to an array, so it looks like:

    a =
    [] -> [][][]
    [] -> [][][]
    [] -> [][][]

    To access an element, you have to access the row which returns a
    reference to the array of columns

    $ra = $a[1]; # access row index 1 and store reference to array of columns

    Then to get the item in a specific column, you dereference the array:

    $ra->[1]; # dereference and access element 1

    To do it all in one step:

    $a[1]->[1];

    or, just:

    $a[1][1];

    Regards,
    Randy.




    Randy Guest

Similar Threads

  1. DataSet not storing any data?
    By Vanth SpiritWalker in forum Macromedia Flash Data Integration
    Replies: 0
    Last Post: October 19th, 12:30 PM
  2. Storing server side information into a javasript array
    By patb96 in forum Macromedia ColdFusion
    Replies: 1
    Last Post: May 26th, 12:48 AM
  3. Weird problem of storing the data format
    By rick in forum ASP Database
    Replies: 1
    Last Post: January 13th, 01:34 PM
  4. Storing encrypted data
    By K Old in forum PERL Beginners
    Replies: 0
    Last Post: August 31st, 03:15 AM
  5. storing an array in a db
    By Alexander Ross in forum PHP Development
    Replies: 3
    Last Post: August 7th, 08:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139