The following section of code is working as expected…
create table todel (id int not null auto_increment, name varchar(100), primary key (id));
insert into todel values (NULL, '24');
select @myid:=last_insert_id();
insert into todel values (NULL, @myid);
mysql> select * from todel;
+----+------+
| id | name |
+----+------+
| 1 | 24 |
| 2 | 1 |
+----+------+
But the same code does not work when I try to wrap it in perl code.
vi myperl.pl
#!D:\Perl\bin\perl
open (output_file, ">myperl.txt");
@Program_ID = '24';
print output_file
"create table todel (id int not null auto_increment, name varchar(100), primary key (id));
insert into todel values (NULL, '@Program_ID');
select @myid:=last_insert_id();
insert into todel values (NULL, '@myid');";
close(output_file);
It generates the code as shown below. The mysql variable name @myid is missing.
# cat myperl.txt
create table todel (id int not null auto_increment, name varchar(100), primary key (id));
insert into todel values (NULL, '24');
select :=last_insert_id();
insert into todel values (NULL, '');
How do I let perl know that I do not want to replace the mysql variable? I want to replace the @Program_ID variable though.
Try