When you print() an array, do not put it in quotes unless you want Perl to
put the default record separator between each element of the array.  Take
out the double-quotes and it will come out the way you want.

-----Original Message-----
From: Jose Malacara
To: [EMAIL PROTECTED]
Sent: 11/20/02 11:31 PM
Subject: output from an array

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]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to