in reply to Storing the results of a SQL select query that reutrns more than one row into a perl array

None of the examples you've given are valid for storing the results of a SQL select query - because none of them perform an SQL query but simply save a string in a variable (this is akin to writing "REALLY FAST CAR" on a piece of paper and then expecting that paper to win the Gran Prix.) As has been pointed out, you need to use a mechanism - e.g., the DB client directly, or the DBI module - which will perform that query. Here's an example of what that might look like:

# Silly example, but fits the spec my @languages = qx#echo "select Language from CountryLanguage where Co +untryCode='RUS'"|mysql -u username database_name#;

Another example, more in line with how it would usually be coded:

#!/usr/bin/perl -w use strict; use DBI; $|++; my %info = ( db => "database_name", user => "username", pass => "pAsSwOrD" ); my $dbh = DBI->connect("DBI:mysql:$info{db}", $info{user}, $info{pass} +); my $ref = $dbh->selectall_arrayref("select Language from CountryLangua +ge where CountryCode='RUS'") or die $DBI::errstr; my @languages = map { $_->[0] } @$ref; # Store the first element (' +Language') in array
Update: Saved the return as an array rather than printing it.

--
"Language shapes the way we think, and determines what we can think about."
-- B. L. Whorf
  • Comment on Re: Storing the results of a SQL select query that reutrns more than one row into a perl array
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Storing the results of a SQL select query that reutrns more than one row into a perl array
by ajguitarmaniac (Sexton) on Dec 20, 2010 at 07:27 UTC

    Thanks Folks!! Funny analogy that, paper winning the gran(d) prix!! lol!! Thank you !!