Can someone please tell me what I'm doing wrong here?
I have a data file that looks like this:
jason,texas,austin
tim,denver,colorado
jose,oregon,portland
And a script to update the last field and output the results with the
new city:
#!/usr/bin/perl -w
open(DATAFILE, "datafile") || die "Unable to open file!\n";
@datafile = <DATAFILE>;
close(DATAFILE);
print "Enter a name (jason, tim, jose): ";
$person = <STDIN>;
chomp ($person);
print "Enter their new city: ";
$city = <STDIN>;
#chomp ($city);
foreach $line (@datafile) {
if ($line =~ /$person/) {
@words = split(",", $line);
$words[2] = $city;
$" = ",";
$line = "@words";
} # end if
push(@newdata, $line);
} # end foreach
print "@newdata";
I am expecting to see the output in the same original format, but I keep
getting this instead:
jason,texas,austin
,tim,denver,boulder
,jose,oregon,portland
I am just not sure why all lines after the first begin with a space
(thus a comma)
Any help would be greatly appreciated!
Jose
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]