in reply to Re: Push array into array of arrays
in thread Push array into array of arrays

Added strict and warnings
#!/usr/bin/perl5.14.1 use DBI; use Data::Dumper; my @data; my $dbh = DBI->connect("DBI:host", 'name', 'pw', { RaiseError => 1, AutoCommit => 1 }, ); my @tesxt = ('perl','python','pearl', 'pear', 'pink', 'pong'); my @array1 = ('fan','friend','fang', 'fun', 'food', 'flow'); my @array2 = (21,22,23,14, 15, 16); my @array3 = ('oh','orange','okay','ostrich', 'open', 'osaka'); my @jumpjump= ($tesxt[0], $tesxt[2], $tesxt[3], 'kit','kat',7); push (@data, \@tesxt); push (@data, \@jumpjump); push (@data, \@array1); push (@data, \@array2); push (@data, \@array3); splice (@jumpjump); @jumpjump= ($tesxt[0], $tesxt[2], $tesxt[3], 'koo','kaa',7); push (@data, \@jumpjump); print Dumper \@data; my $sth = $dbh->prepare("insert into table_test (just, random, field, +for +, testing, purposes) values (?, ?, ?, ?, ?, ?)"); $dbh->begin_work(); foreach my $row (@data) { $sth->execute(@$row); } $dbh->commit(); $dbh->disconnect;

Replies are listed 'Best First'.
Re^3: Push array into array of arrays
by Anonymous Monk on Dec 20, 2018 at 02:37 UTC
    $VAR1->1 is the array of arrays. but since it has different values, how can i ensure it to be inserted, without overriding the previous ?
      how can i ensure it to be inserted, without overriding the previous ?

      Copy @jumpjump to a new anonymous array and insert its reference into @data.

      #!/usr/bin/perl5.14.1 use strict; use warnings; use Data::Dumper; my @tesxt = ('perl','python','pearl', 'pear', 'pink', 'pong'); my @jumpjump = ($tesxt[0], $tesxt[2], $tesxt[3], 'kit','kat',7); my @data = (); push @data, \@tesxt; push @data, [@jumpjump]; splice (@jumpjump); @jumpjump = ($tesxt[0], $tesxt[2], $tesxt[3], 'koo','kaa',7); push @data, [@jumpjump]; print Dumper \@data;
      poj
        omg wow @poj ! thank you very much !! how amazing this anonymous array solved my 2-day-old issue ! amazing square brackets ! thanks ! It works !