sub get_user_data { # This subroutine collects the users data from the user database print p("START of get_user_data") if $DEBUG; my @internal_user_data = @_; # This line takes the user_data passed to us from the previous routine (@_) and allocates it to our internal user data array my $entered_id = $internal_user_data[0]; # just so that it is clearer later we create a variable from the passed data # Use DBI to connect to the users.csv datafile #----------------------------------------------- my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); # tell DBI we want to use the Anydata module in ./MyLibs $dbh->func( 'users', 'CSV', 'data/users.csv', 'ad_catalog'); # Connect to the users.csv data file # select from the datafile the id for the user ID from the array paased from the previous sub routine my @params = ($entered_id); # Theese are the parameteres we will use in the SQL command above my $sql = "SELECT * FROM users WHERE id = ?"; # this is the SQL command we want to execute print "$sql\n[@params]\n" if $DEBUG; # if we are in debug mode print the SQL statement my $sth = $dbh->prepare( $sql ); # prepare the SQL command $sth->execute( @params ); # excecute the SQL using our parameters my @result = $sth->fetchrow_array; # this line takes the results of the select and puts it in the array called RESULTS $dbh->disconnect(); # we are done with the datbase for now, so disconnect from it (MAY NOT BE NECESSARY) print p("result = @result")if $DEBUG; # Prints the result of our SQL command if we are in debug mode. return (@result); print p("END of get_user_data") if $DEBUG; }