radhika wrote:
> Hi,
> 
> I am trying to create this data structure as below:
> 
> $perl = [
>     {
>                 fname           => 'Fred',
>                 lname           => 'Flintstone',
>                 residence       => 'Bedrock'
>     },
>     {
>                 fname           => 'Barney',
>                 lname           => 'Rubble',
>                 residence       => 'Bedrock'
>     }
>   ];
> 
> 
> I have a couple of questions. a) What is it called. Is it an array of
> hashes that is being stored in a scalar?

Yes, you could call it that. $perl is a reference to an array, each element
of which is a reference to a hash.

> b) How can I create it from the data I have. Currently I have created
> a single record, (see below), but I am having trouble understanding
> how I can turn my $record below into a data structure like the one in
> the above example.
> I have managed to create a single record like this:
> 
> while(@row = fetchrow_array0
> {
> $record = {
> TRADE_DATE      => $row[0],
> TRADE_TIME      => $row[1],,
> FIRSTNAME       => $row[2],
> LASTNAME        => $row[3],
> EXCHANGE        => $row[4],
> SYMBOL          => $row[5],
> };
> }

You could do it like this:

    while (@row = fetchrow_array()) {
       push @$perl, {
            TRADE_DATE      => $row[0],
            TRADE_TIME      => $row[1],
            FIRSTNAME       => $row[2],
            LASTNAME        => $row[3],
            EXCHANGE        => $row[4],
            SYMBOL          => $row[5],
       };
    }

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to