Hi!
I'm currently working on some kind of blogging technology for my website, and I'm having problems with a multidimensional data-structure used in a function to parse templates and output pages.
All data in the program is stored in an anonymous hash "bound" to a scalar ( [tt]my $self = {};[/tt] (yes, I'm trying to do object-oriented programming )).
So, I have an SQL query that pulls out an row of a database:
[tt]$self {sth} = $self {dbh}->prepare('select * from comments where id = ?');[/tt]
This statement is executed, and then I call fetchrow_hashref() as shown below:
[tt]$self {comments} [ $self {i} ] = $self {sth}->fetchrow_hashref();[/tt]
fetchrow_hashref() is executed in a while loop (together with the execution of the statement handle), and the fetched data stored in an array of hashes.
There must be some error in this line, because I am notified at runtime that it is "Not an ARRAY reference" when I try to do a [tt]print ${ $self {dataStructure} } [0] . "\n";[/tt] (The first (zeroth) slot of the array should be populated, since all while loops start at zero and increments by one for each iteration). The fetchrow_hashref() function works perfectly fine if I skip the array population part, like this: [tt]$self {post} = $self {sth}->fetchrow_hashref();[/tt].
So, is it a syntactical error? Or am I having problems dereferencing the variable? (It should be said that $self {dataStructure} is later passed into another function / subroutine as a reference, where the data is to be used).
I hope this explanation is understandable in spite of my bad English,
I will publish the relevant source code if anyone is interested.
Best regards,
Jo Andreas.
I'm currently working on some kind of blogging technology for my website, and I'm having problems with a multidimensional data-structure used in a function to parse templates and output pages.
All data in the program is stored in an anonymous hash "bound" to a scalar ( [tt]my $self = {};[/tt] (yes, I'm trying to do object-oriented programming )).
So, I have an SQL query that pulls out an row of a database:
[tt]$self {sth} = $self {dbh}->prepare('select * from comments where id = ?');[/tt]
This statement is executed, and then I call fetchrow_hashref() as shown below:
[tt]$self {comments} [ $self {i} ] = $self {sth}->fetchrow_hashref();[/tt]
fetchrow_hashref() is executed in a while loop (together with the execution of the statement handle), and the fetched data stored in an array of hashes.
There must be some error in this line, because I am notified at runtime that it is "Not an ARRAY reference" when I try to do a [tt]print ${ $self {dataStructure} } [0] . "\n";[/tt] (The first (zeroth) slot of the array should be populated, since all while loops start at zero and increments by one for each iteration). The fetchrow_hashref() function works perfectly fine if I skip the array population part, like this: [tt]$self {post} = $self {sth}->fetchrow_hashref();[/tt].
So, is it a syntactical error? Or am I having problems dereferencing the variable? (It should be said that $self {dataStructure} is later passed into another function / subroutine as a reference, where the data is to be used).
I hope this explanation is understandable in spite of my bad English,
I will publish the relevant source code if anyone is interested.
Best regards,
Jo Andreas.