Perl noob is here. I have a small script (see below) that I use to create a MySQL INSERT statement.
use strict;
my @records = qw/Record1 Record2 Record3/;
my $insert = "
INSERT INTO table
VALUES
";
foreach my $record (@records) {
$insert .= "('" . $record . "'),\n ";
}
print "$insert\n";
Current output
INSERT INTO table
VALUES
('Record1'),
('Record2'),
('Record3'),
I need to know how to split the last element of an array @recordsand add ;instead,
Desired output
INSERT INTO table
VALUES
('Record1'),
('Record2'),
('Record3');
source
share