Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
I used the below link to get the code to get the contents of MS Access table. In the link below go to "Putting it all together section" http://sunsite.berkeley.edu/ead/tools/eaddb/fundamentals.html.

The problem is that i get an error

Can't call method "value" on an undefined value at my_program.pl line + 9.

The code is

my $value = $RS-> Fields($field)->value;

so i checked on the internet if anyone else found the same problem. I found a link which had given a solution too. The link is http://aspn.activestate.com/ASPN/Mail/Message/perl-win32-database/1700169 The solution given was if you want to access an object's property you have to put braces around the property. so Line 24:

my $value = $RS-> Fields($field)->value;

should be: Line 24:

my $value = $RS-> Fields($field)->{value};

I tried the above but still i get the error.

20070815 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: Connecting to MS Access
by Burak (Chaplain) on Aug 10, 2007 at 12:06 UTC
    You should try DBI with DBD::ADO to get a Perlish and DBI-ish interface ;)
Re: Connecting to MS Access
by jdporter (Paladin) on Aug 10, 2007 at 13:27 UTC

    What is the value of $field? It has to be the name of one of the fields (columns) in the table. Did you set it to "field", as in the example? That would be incorrect, and would produce the error you got, unless by chance you also had a column named "field".

    Your supposed solution, putting {value} in braces, would not have solved this problem in any case. It's only necessary on property assignment.

    A word spoken in Mind will reach its own level, in the objective world, by its own weight
Re: Connecting to MS Access
by CountZero (Bishop) on Aug 10, 2007 at 20:58 UTC
    It is a bad tutorial, they don't get a cookie!

    It doesn't use strict;; it never tests for errors when opening the database or when retrieving or updating data; ...

    Far better indeed to drop this and study how to use databases the DBI way.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James