use strict; use warnings; my @numbers = (1,2,3,4); my @data; # Example Data. for my $i (0..$#numbers) { @{$data[$i]} = ( $numbers[$i] ); } for my $i (0..$#data) { print FINAL " CREATE TABLE bce.week_g${last_4_chars}v00_temp" . ($i+1) . " AS SELECT DISTINCT(a.FILEDATE), a.RPTSTORE, b.LOC_N FROM bce.week WHERE ID in (" . join(', ', @{$data[$i]}) . "); "; }
Note the use of strict and warnings.
Note the use of join to seperate the IDs with commas.
Note the lack of hardcoding of the number of elements.
Note how capitalization and alignement makes the SQL stmt much more readable.
Updated to use code from OP.
In reply to Re^3: Adding a number from scalar variable to array name
by ikegami
in thread Adding a number from scalar variable to array name
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |