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:
Update: Saved the return as an array rather than printing it.#!/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
In reply to Re: Storing the results of a SQL select query that reutrns more than one row into a perl array
by oko1
in thread Storing the results of a SQL select query that reutrns more than one row into a perl array
by ajguitarmaniac
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |