learingperl01
MIS
Hello everyone I am hoping someone can point me in the right direction as I am a little confused at the moment with what I am trying to do. I am trying to perform a sql query which reads some input from another file. They problem that I am having or probably just not doing right is I want to save all results to an array which I will used to sort certain fields. I am not sure if I am saving or how to save all results to an array for later use. I have tried the following but when I print to view the results I don't get all the rows just the first. Also it appears that when I saved it to an array I get dup results. Below is the script which is currently working when printing the results directly not from an array.
Thanks for the help!!
Thanks for the help!!
Code:
my @lines = read_file('/tmp/test.txt');
chomp(@lines);
my $sql = q|select * from table_name where srcaddr = ? or dstaddr = ?;
foreach my $line (@lines) {
$sth->execute($line, $line) or die "Can't execute SQL statement: $DBI::errstr\n";
my @all_rows;
while (($line) = $sth->fetchrow_array()) {
push(@all_rows, $line);
foreach (@all_rows) {
print "$_\n";
}
}
}