I am trying to loop through two equally sized arrays, and replace a string with the elements found at each index.
The loop is only doing the first element.
#!/usr/bin/perl
use strict;
use warnings;
# SQL statement for string replace
my $insert = "INSERT INTO table ( JOB, URI ) VALUES ( 'JOB', 'URL' );";
#array of jobs
my @jobs = ("job1", "job2");
#array of url's
my @urls = ("http://www.yahoo.com", "http://www.google.com");
# for each job replace the "URL" with a url from
# the url array, then print the new sql insert statement
for( my $i = 0; $i <= $#jobs; $i++ ){
$insert =~ s/URL/$urls[$i]/g;
print $insert."\n";
}
EDIT- Using $i<=$#urls now has the correct loop size, but the call to $urls[$i] never gets a different element in that array. Its always the same element
I think this is an issue with the string replace I am doing, the loop will print out the elements as expected, but not when I use the counter in the string replace.