in reply to Re^3: Selecting DB
in thread Selecting DB

it worked, but am getting emails like this

test@test.com test2@test2.com

no comma, coz i wanted to join emails with comma

Replies are listed 'Best First'.
Re^5: Selecting DB
by NetWallah (Canon) on Jul 08, 2023 at 15:50 UTC
    If you want all the emails comma (and possibly comma + newline) separated, avoid the foreach loop, and simply concatenate the results:
    my $rez = join(",\n", @$user1, @$user2); # Remove the \n if you want + just CSV

                    "These opinions are my own, though for a small fee they be yours too."

      this option just output this error

      ARRAY(0x559d1462e390), ARRAY(0x559d1462e348)

        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.