Well, it's "just start over" broken, but if you want to keep it the way it is and just make it work with as few changes as possible, this should do:
print "This is the list of address\n",
"here are the addresses\n";
while (<INFILE>) {
my($line) =$_;
chomp($line);
while ($line =~ /(address............)/g )
{
my @values = split(' ', $line);
foreach my $val (@values) {
next;
print "$val\n";
}
print "$1\n";
}
}
You'll note I added two print statements, a next, changed an if( to a while(, and added a /g to your regex. The rest is untouched. If your input data is what you say it is in your original post (a single line of text containing multiple address fields), this works fine and lets you feel like the original code didn't change much.
If it doesn't work, go back and verify that your input data looks exactly like what you posted in your original question.
|