You're just not quite doing enough de-referencing...

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11153321 use warnings; use DBI; $SIG{__WARN__} = sub { die @_ }; my $dbname = '/tmp/d.11153321'; unlink $dbname; my $dbh = DBI->connect_cached( "DBI:SQLite(RaiseError=>1,PrintError=>0):$dbname"); while() { my ($table) = split ' ', <DATA> // last; <DATA>; my (@fields) = split ' ', <DATA>; my $fieldnames = join ', ', map "$_ text", @fields; my $fields = join ', ', @fields; $dbh->do("create table $table ($fieldnames)"); while( <DATA> ) { /\S/ or last; my $values = join ', ', map "'$_'", split; $dbh->do("insert into $table ($fields) values ($values)"); } } system "sqlite3 $dbname .dump"; ###################################################################### +####### my $AID = "XD4555"; my $query = $dbh->prepare("SELECT snd.EMAIL FROM FUSERS as m JOIN USERS as snd ON snd.USERID = m.USERID WHERE (m.USERID_IM = ?)"); $query->execute($AID); my $user1 = $query->fetchall_arrayref(); my $query_other = $dbh->prepare("SELECT snd.EMAIL FROM FUSERS as m JOIN USERS as snd ON snd.USERID = m.USERID_IM WHERE (m.USERID = ?)"); $query_other->execute($AID); my $user2 = $query_other->fetchall_arrayref(); use Data::Dump 'dd'; dd {user1 => $user1, user2 => $user2}; my $TotalEmails = [ @$user1, @$user2 ]; use Data::Dump 'dd'; dd {TotalEmails => $TotalEmails}; for my $em ( @$TotalEmails ) { my $rez = join ',', @$em; print "$rez\n"; } #my $TotalEmails = $user1 + $user2; # #foreach my $em ( $TotalEmails ) { # my $rez = join( ",", $em); # print "$rez\n"; # } __DATA__ USERS ID USERID EMAIL 1 XD4555 JOHNE@DEO.COM 2 JJKKKK JANE@DEO.COM 3 JJKKKK JANE21@DEO.COM FUSERS ID USERID USERID_IM 1 XD4555 JJKKKK 2 JJKKKK TYYUPPO

Outputs:

PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE USERS (ID text, USERID text, EMAIL text); INSERT INTO USERS VALUES('1','XD4555','JOHNE@DEO.COM'); INSERT INTO USERS VALUES('2','JJKKKK','JANE@DEO.COM'); INSERT INTO USERS VALUES('3','JJKKKK','JANE21@DEO.COM'); CREATE TABLE FUSERS (ID text, USERID text, USERID_IM text); INSERT INTO FUSERS VALUES('1','XD4555','JJKKKK'); INSERT INTO FUSERS VALUES('2','JJKKKK','TYYUPPO'); COMMIT; { user1 => [], user2 => [["JANE21\@DEO.COM"], ["JANE\@DEO.COM"]] } { TotalEmails => [["JANE21\@DEO.COM"], ["JANE\@DEO.COM"]] } JANE21@DEO.COM JANE@DEO.COM

The Data::Dump output is there to see what the returned data really is. You could also use Data::Dumper, but I just prefer the ease of Data::Dump.


In reply to Re^7: Selecting DB by tybalt89
in thread Selecting DB by frank1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.